Prabhu
Prabhu

Reputation: 927

How to pass values for multi select custom fields using RESTlet in Netsuite?

I can pass values for select, text box and etc but not for multi select. I can update values for multi select. But i can't create a record by passing values for multi select.

This is the code :

$datastring = array(
        "gu_action"=> "create",
        "recordtype"=>"vendor",
        "companyname"=>"Jerald Vend",
        'subsidiary'=>1,
        'custentity36'=>1
);

custentity36 is multiselect control. It's label is Course

when i pass single value , It works fine. when i try to pass multiple values for multi select like the below code , i am getting error like "Please enter value(s) for: Course"

$datastring = array(
        "gu_action"=> "create",
        "recordtype"=>"vendor",
        "companyname"=>"Jerald Vend",
        'subsidiary'=>1,
        'custentity36'=>array(1,3)
);

The Code is : https://gist.githubusercontent.com/ganeshprabhus/a3ebd67712913df3de29/raw/3a6df6a3af8642fceacb3a4b8e519ad96a054e69/ns_script.js

Upvotes: 0

Views: 2739

Answers (1)

Frederick RajKumar
Frederick RajKumar

Reputation: 228

The value you pass is in correct format. In this case the RESTlet code should have the compatibility of handling the multiselect filed. The field set value api that used in the RESTlet should be

nlapiSetFieldValues()

This is the api can be used to set multiselect field value. As per the github refernce you shared. under the create_record function

/********************** Creation *********************************/
function create_record(datain) {
    var err = new Object();

    // Validate if mandatory record type is set in the request
    if (!datain.recordtype) {
        err.status = "Failed";
        err.message = "Missing recordtype";
        return err;
    }

    var record = nlapiCreateRecord(datain.recordtype);

    for ( var fieldname in datain) {
        if (datain.hasOwnProperty(fieldname)) {
            if (fieldname != 'recordtype' && fieldname != 'id') {
                var value = datain[fieldname];
                // ignore other type of parameters
                if (value && typeof value != 'object') {

record.setFieldValue(fieldname, value);

}
            } //recordtype and id checking ends
        }
    } //for ends

    var recordId = nlapiSubmitRecord(record);
    nlapiLogExecution('DEBUG', 'id=' + recordId);

    var nlobj = nlapiLoadRecord(datain.recordtype, recordId);
    return nlobj;
}

The quoted code should be

record.setFieldValues(fieldname,value) // fieldname : custentity36 , value : 1,3

Upvotes: 5

Related Questions