0

I have a page in SharePoint that builds a bunch of tables using JavaScript. I need to get the selected value of a multi-select field from a list and write that value to a column in a table. I've got all the other values I need, but this one either throws an error or returns [Object Object] depending on how I write it.

fieldValue = listItemArray[i].get_item(listFieldArray[j].fieldInternalName);

returns [Object Object] and when I expand fieldValue in the watch list in my browser debugger, it returns only the first option in the list, not the selected value, but still writes [Object Object] to the page.

Gholamali Irani
  • 4,391
  • 6
  • 28
  • 59

2 Answers2

0

Here is the answer that worked:

Custom Lookup Field

More specifically:

                value = listItemArray[i].get_item(listFieldArray[j].fieldInternalName);
            for (var z=0; z<value.length; z++) {
            var valueLU=value[z];
            fieldValue=valueLU.get_lookupValue();
            }
0

multi select field returns the array of all the selected choices. So you will have to iterate this array to access all the objects present.

again selected choices will be the object as Lookup field stores object (e.g. 5;#someValue) not the actual value. IT has two properties

lookup Id (5)

Lookup Value (someValue)

Refer this link for more information - SharePoint JavaScript CSOM: Best way to deal with Lookup fields?

Try below code. It should work for you:

objLength = oListItem.get_item('MultiLookup').length;

for(var i=0; i<objLength; i++){
    oListItem.get_item('MultiLookup')[i].get_lookupValue();
    //oListItem.get_item('MultiLookup')[i].get_lookupId();
}

Note :

MultiLookup is the internal name of the multi select field.

Rohit Waghela
  • 844
  • 3
  • 11
  • 21