Set Multi Lookup value - Error in Edit-Form with special characters

Discussions about Cross-site Lookup
Locked
ragesoft
Posts: 50
Joined: Fri Feb 23, 2018

27 Aug 2019

Hi there,

i'm setting a cross-site lookup with multi-value option by code in the new form:

Code: Select all

		var data = {};
			var titleField="WikiChapterTitle"; //internal field name for lookup-column
			data["Id"] = item.ID;
			data[titleField] = item[titleField];
			fd.field("WikiKapitel").value([data]);
It works.

The value from "titleField" is "InputSystem <-> OutputSystem"


But, if i try to update a item, i receive an error:
"Something went wrong..."
"The data source control failed to execute the update command"

The data from "fd.field("WikiKapitel").control('data')" in edit-view:

Code: Select all

[
   0: {
      [functions]: ,
      Id: "174",
      WikiChapterTitle: "InputSystem &lt;-&gt; OutputSystem"
   },
   length: 1
]
after set manuale (dropdown):

Code: Select all

[
   0: {
      [functions]: ,
      __metadata: { },
      ID: 174,
      Id: 174,
      WikiChapter: "   4.  39.",
      WikiChapterTitle: "InputSystem <-> OutputSystem"
   },
   length: 1
]
The problem seems to be because of the "<" & ">" characters...

How to fix this issue?

User avatar
mnikitina
Posts: 264
Joined: Wed Jun 05, 2019

29 Aug 2019

Hello ragesoft,

I'm sorry for the delayed reply.

Could you please give more details about the error: "Something went wrong..."
"The data source control failed to execute the update command".

When do you see this error?
Is it occur only when 'WikiKapitel' field value is 'InputSystem <-> OutputSystem'.

Could you please send the screenshot of the error and the fields to have a clear picture.

ragesoft
Posts: 50
Joined: Fri Feb 23, 2018

09 Sep 2019

The problem is with the escaped values.

So if i would add the field with "&gt;" or "&lt;" it dosnt work!

in Edit form if i call "fd.field("WikiKapitel").control('data')" i see:

Code: Select all

{
   [functions]: ,
   Id: "174",
   WikiChapterTitle: "InputSystem &lt;-&gt; OutputSystem"
}
i believe the ampersand makes the different here.
It should be removed / escaped whatever...

until now my workaround is to clear the title in the onsubmit function to a default text:

Code: Select all

var chapters = fd.field("WikiKapitel").value();
	var data = [];
	
	for(var i in chapters){
		var item = {};
		item.Id = chapters[i];
		item[titleField] = "TmpTitle";
		data.push(item);
	}
	fd.field("WikiKapitel").value(data);
	

User avatar
mnikitina
Posts: 264
Joined: Wed Jun 05, 2019

10 Sep 2019

ragesoft,

You can update multichoice lookup field with ID only, using the below code, so you will not use text value in your code.

Code: Select all

var ID = 3;
// select element by ID:
fd.field('MultiLookup').control()._el().find('select:eq(0)').val(ID); 

// add button click:
fd.field('MultiLookup').control()._el().find('button:eq(0)').click();

ragesoft
Posts: 50
Joined: Fri Feb 23, 2018

10 Sep 2019

NO.
I don't usually need Code to set the field.
I'm only set the field in new-form because of a user action inside a wiki page.

The problem is the edit form.
If i don't use any code behind, i can't save the form, if it is initiated with a lookup-value that is defined as e.g. "Input <-> Output" or what ever...

I believe the problem comes with the lookup itself!
On init it try to escape the display value!?

You can easily reproduce the error:
Create "ListA"
Add items to it (just the title):
- "A <-> B"
- "C"
Create "ListB"
Add Column "LookupListA" pointing to ListA with "Title" as show field
Make it a csl with multi-select option
Add a new item to it:
- "Item 1" with LookupListA "A <-> B" selected
Save
Reopen "Item 1" for edit
Just try to save it => error

This is why i need the workaround here with code behind...

Greetings

User avatar
mnikitina
Posts: 264
Joined: Wed Jun 05, 2019

12 Sep 2019

ragesoft,

I think the problem is in the "titleField" from which you are getting "InputSystem <-> OutputSystem" text for 'WikiKapitel' multichoice lookup filed.

What is the "titleField" field type? What do you see in the console when calling its value?

Please try to set 'WikiKapitel' multichoice lookup filed value in the New Form with the following code and see if you will get the error or not.

If it is Cross-site lookup field:

Code: Select all

fd.field('WikiKapitel').value([{Id: 174, Title: 'InputSystem <-> OutputSystem'}]);
If it is Default lookup field:

Code: Select all

var ID = 174;
// select element by ID:
fd.field('test').control()._el().find('select:eq(0)').val(ID); 

// add button click:
fd.field('test').control()._el().find('button:eq(0)').click();
You can check the field type in Forms Designer, field settings.
field.PNG
field.PNG (25.28 KiB) Viewed 11863 times

In case the error is still occurring, please provide more details to troubleshoot the issue.

- What Sharepoint version you are using? Is it Online or On-premises?
- What is the version of Forms Designer?
- Could you please share the whole code you are using to set 'WikiKapitel' value, clarify the field types and send the screenshots of the form.

Locked
  • Information
  • Who is online

    Users browsing this forum: No registered users and 6 guests