10

I want to set the value for the multi-select with existing values in that field. (i.e) If the Filed has the values "A , B" means I wants add the New Value "c" with Existing Values So, Result would be "A,B,C" .

I used "N/Record' Modules SubmitFields API to set the value for the Multi-select Field like this

CODE : SuiteScript 2.0 version :

Initial Code:

var strArrayValue = new Array();
    strArrayValue [0] = "A";
    strArrayValue [1] = "B";
    strArrayValue [2] = "C";


record.submitFields({
         type:'purchaseorder',
         id:56,
         values:{

         custbody_multiselectfield: strArrayValue 

         },
         options: {
            enableSourcing: false,
            ignoreMandatoryFields : true
          }

});

It is showing the error like this : "you have entered an Invalid Type Argument :arg 4"

Updated Code :

 var strArrayValue = new Array();
        strArrayValue [0] = "A";
        strArrayValue [1] = "B";
        strArrayValue [2] = "C";

   var PORec = record.load({               // Loading Purchase Order Recod

                type:"purchaseorder",
                id:56,
                isDynamic: true

                 )};

        PORec.setValue('custbody_multiselectfield',strArrayValue ); // Setting Value (Array List) for Multi-Select Fields

        PORec.save();    // Saving Loaded Record

It is also showing the error: " Invalid custbody_multiselectfield'reference key 31567,31568 "

But if I add an Value as an String instead of String Array it is setting only single value (i.e) overriding the previous values. Ex: Multi-select has only the "C" value instead of "A,B,C" Values.

Can anyone help regarding this question.

Deepan Murugan
  • 721
  • 2
  • 19
  • 41

3 Answers3

10

According to NetSuite's documentation, you cannot use this api method to edit or submit select fields - only fields that support inline editing (see SuiteAnswer ID:45158). You may have to load the record with record.load(), modify the values and then submit with record.save().

EDIT: In answer to the updated question, the only thing that appears amiss here is that you are trying to set the values by the display value of the field, where setValue() is expecting the Internal ID of the values. You can either change the values you're populating with the relevant internal IDs, or you could change it to use the setText() method instead:

var strArrayValue = new Array();
        strArrayValue [0] = "A";
        strArrayValue [1] = "B";
        strArrayValue [2] = "C";

   var PORec = record.load({               // Loading Purchase Order Recod

                type:"purchaseorder",
                id:56,
                isDynamic: true

                 });

        PORec.setText('custbody_multiselectfield',strArrayValue ); // Setting Value (Array List) for Multi-Select Fields

        PORec.save();    // Saving Loaded Record

I tested both these approaches and both work for me.

Krypton
  • 4,394
  • 2
  • 9
  • 13
  • Thanks Krypton , I tried to set the value for the multi-select filed using the 'N/Record' Load Module and used setValue method. and set the Value as an Array type but it is showing the Error " Invalid custbody_multiselectfield'reference key 31567,31568. but instead of Array List if i used single string variable it setting the value. but i want add new values by appending with existing value in the multi-select field.Is there any other way to achieve it. – Deepan Murugan Apr 23 '17 at 13:59
  • Can I recommend submitting a new question with your updated code? – Krypton Apr 24 '17 at 15:29
0

If using a client script setting multiselect values is simple. In my case I was searching for subordinates of an employee. For each result I push the internalid of the subordinate (employee record) to an array. Then on my multiselect field of type 'Employee' I set the values like below:

var subordinates = [];

// do search and push internalids of employees

currentRecord.setValue({
  fieldId: 'custrecord_emp_subordinates',
  value: subordinates
});

Hopefully this helps someone!

Skromak
  • 490
  • 6
  • 12
0

If you are loading the record everytime you want to update the multi-select field value, you can fetch the data in the field and store it in a variable.

var multiSelectData = record.getValue({
   fieldId:''
});

The data will be in the form of an array, so you can push your data in the array.

multiSelectData.push(yourData);

Finally, you can submit the this variable and save the record.

record.setValue({
   fieldId:'',
   value: multiSelectData
});

Note - Please take care of the datatypes. Typecast if required.

Sayeesh
  • 208
  • 1
  • 3
  • 13