Copying matrix item and setting the value of a multiselect field

I’m using record.copy to copy an existing matrix item to create a new record and update a couple of fields with values for the newly copied record. The matrix item has a custom field that’s multiselect type representing length.

I can’t figure out how to set the value of the new record to get it to save properly. I keep getting an error of this type:

Invalid item option custitem_size for item xxxx

My code is:

var newRecord = record.copy({
            type: ‘inventoryitem’,
            id: 17386,
            isDynamic: false
        });
newRecord.setValue(‘custitem_size’, ??????);
var recordId = newRecord.save();
I tried several values for ?????? but I still get errors.
Beginner Asked on February 4, 2020 in SuiteScript.
Add Comment
4 Answer(s)

Its the syntax: See the below

 

newRecord.setValue({fieldId:‘custitem_size’,Value: ??????});

Beginner Answered on February 4, 2020.
Add Comment

I’m still getting the same error message even with the explicit declaration of the object properties.

Beginner Answered on February 4, 2020.
Add Comment

You are better off creating your own matrix item rather than trying to copy another. Matrix items have some  non-standard fields that need to be set.

Checkout the SuiteAnswer article at: https://netsuite.custhelp.com/app/answers/detail/a_id/38898

 

Intermediate Answered on February 4, 2020.
Add Comment

Thanks battk. I’m trying to use record.copy since most of the data from the source record (which is already a child record) is the same on the new matrix record with the exception of length or size which is represented by the custom field.

Since I could not get it to work, I finally used record.create ad populated the fields I needed and the only time it worked to save the record is when I included a value in externalid because previous attempts were unsuccessful (hence the need to try record.copy) as I was getting a DUP_ITEM error message every single time I tried creating and then saving the record.

Beginner Answered on February 4, 2020.

You probably still need to set the non standard matrix option fields to new values.

on February 4, 2020.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.
  • This site made possible by our sponsors:   Tipalti   Celigo   Limebox   Become a Sponsor