最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to set value for the multi-select field using netsuite suitescript 2.0 version? - Stack Overflow

programmeradmin4浏览0评论

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.

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.

Share Improve this question edited Apr 25, 2017 at 11:58 Deepan Murugan asked Apr 23, 2017 at 6:48 Deepan MuruganDeepan Murugan 7713 gold badges22 silver badges42 bronze badges
Add a comment  | 

3 Answers 3

Reset to default 12

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.

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!

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.

发布评论

评论列表(0)

  1. 暂无评论