2016-04-05 34 views
0

我可以通過選擇,文本框等的值,但不適用於多選。我可以更新多選的值。但是我無法通過傳遞多重選擇值來創建記錄。如何在Netsuite中使用RESTlet傳遞多選擇自定義字段的值?

這是代碼:

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

custentity36是多選控制。它的標籤是課程

當我通過單個值,它工作正常。 當我試圖通過多個值多選擇,如下面的代碼,我得到錯誤,如「請輸入值(S)爲:課程」

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

的代碼是:https://gist.githubusercontent.com/ganeshprabhus/a3ebd67712913df3de29/raw/3a6df6a3af8642fceacb3a4b8e519ad96a054e69/ns_script.js

回答

5

值你傳遞的格式正確。在這種情況下,RESTlet代碼應該兼容處理多選字段。在RESTlet中使用的字段設置值api應該是

nlapiSetFieldValues() 

這是可用於設置多選字段值的api。根據你分享的github推薦。下create_record功能

/********************** 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(字段名,值);

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

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

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

所引用的代碼應該是

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

謝謝弗雷德裏克,我用setFieldValues在別的。我也在github中更新了代碼。 – Prabhu

+0

https://gist.githubusercontent.com/ganeshprabhus/a3ebd67712913df3de29/raw/eb2a67c1989181a2b0646083af0913070ad520ee/ns_script.js – Prabhu

+0

感謝Prabhu的評論 –

相關問題