Write multiple choice lookup to SharePoint multiple choice column

I'm working with a SharePoint Lookup field in Plumsail Forms to add multiple options from a separate list based on a lookup value.

image

In the screenshot example above, I'm filtering on the Ultra-Small Desktop (UDT) product category and adding the filtered values in the Upgrade Parts column.
The data format that's getting written back to my SharePoint column appears to be an object:

{"id":24,"text":"Windows 11 Professional, NON-AFIN"},{"id":22,"text":"Intel Core i5-12400 / UHD 730"},{"id":20,"text":"Upgrade to 64GB"},{"id":31,"text":"OCONUS - Upgrade to 64GB"}

My goal is to just get a list of the Upgrade Parts written to a SharePoint field (optimally a multiple Choice field, but even a regular string field is fine) but I can't figure out how to parse it out.

Is this something I can do with Javascript & an onSave() command?

Thanks,

Gabe

Hello @GGiacomo,

Not sure I understood your request. What is the type of the Upgrade Parts column? From which field do you add values to the Upgrade Parts field?

Hi Maragarita -
The fields are:
Product Category = SharePoint Choice field, used to filter values from a separate list
Upgrade Parts = Form lookup field from 2nd list, dependent on Product Category. Multiple items are added here
Upgrades = SharePoint string field containing the object/array data from the Upgrade Parts lookup form field
Upgrade Options = SharePoint Mutiple Choice field

What I'd like to happen:

  1. Select a Product Cateogry from the SharePoint choice field
  2. Select all Upgrade parts from the filtered list form field
  3. On save, populate a SharePoint multiple choice field with the items selected in the Upgrade Parts filtered list form field

The end goal is to get the options from the filtered list form field copied into a SharePoint multiple choice field - hopefully that makes more sense.

@GGiacomo,

Thank you for the details!!

So basically, you want to save the display value of the Lookup field to Multiple choice field before submitting the item. To do so, use this code:

fd.spBeforeSave(function(spForm) {
    const selected = [];
    fd.field('LookupFieldName').value.forEach(element => selected.push(element.LookupValue))
    fd.field('ChoiceFieldName').value = selected;
});

Thanks Maragrita!
One tweak to the code you sent - the LookupFieldName is a control, so I had to change it from fd.field.('LookupFieldName').value to fd.control('LookupFieldName').value

(Just in case anyone comes back to reference this post).

fd.spBeforeSave(function(spForm) {
    const selected = [];
    fd.control('LookupFieldName').value.forEach(element => selected.push(element.LookupValue))
    fd.field('ChoiceFieldName').value = selected;
});