如何使用ScriptSuite在Netsuite中创建采购订单



我是Netsuite的新手,我被要求执行从java编程的应用程序启动的脚本。该脚本具有在Netsuite中生成采购订单的函数和列出前面创建的采购订单的其他函数。事实证明,为此我使用api SuiteScript,但在创建采购订单时运行java应用程序并启动脚本,但它给出了以下错误:

Aug 03, 2015 2:49:00 PM com.gargoylesoftware.htmlunit.WebClient printcontentfnecessaryINFO: {"error": {"code": "user_error", "message": "Please enter value (s) for: Vendor"}}

创建的Javascript函数是:

function CreatePurchase_Orders(datain){
var output = '';
nlapiLogExecution('DEBUG','createRecord','ingreso la consulta' ) ;
    nlapiLogExecution('DEBUG','createRecord', 'Ingresa: '+ datain);
//var msg = validateTimeBills(datain);
var msg = null;
if (msg){
    var err = new Object();
    err.status = "failed";
    err.message= msg;
    return err;
}
var Purchase_Orders = datain.Purchase_Order;
nlapiLogExecution('DEBUG','createRecord', 'obtuvo el objeto: '+ Purchase_Orders);
for (var Purchase_Orderobject in Purchase_Orders){
    var Purchase_Order = Purchase_Orders[Purchase_Orderobject];
    var transdate = Purchase_Order.Transdate;
    var Form = Purchase_Order.Form;
    var Vendor = Purchase_Order.Vendor;
    var Currency = Purchase_Order.Currency;
    var Item = Purchase_Order.Item;
    nlapiLogExecution('DEBUG','campos','transdate: '+ transdate+'/Form: '+Form + ' /Vendor: ' + Vendor + ' /Currency: ' + Currency
                                                            + ' /Item: ' + Item);
    var Purchase_Order = nlapiCreateRecord('purchaseorder');
    var nlobjAssistant =   nlapiCreateAssistant ( 'asistente' , false ) ;
            var Purchase_Orderid =  1;//nlapiSubmitRecord( Purchase_Order , true, true);
            if(Purchase_Order){
                nlapiLogExecution('DEBUG', 'Purchase_Order ' + Purchase_Orderid + ' successfully created', '');
                nlapiLogExecution('DEBUG', 'createRecord', 'creo el record');
            }
    Purchase_Order.setFieldValue('transdate', transdate);
    Purchase_Order.setFieldValue('inpt_customform1', Form);
    Purchase_Order.setFieldValue('vendor', Vendor);
    Purchase_Order.setFieldValue('inpt_currency7', Currency);
    Purchase_Order.setFieldValue('inpt_item', Item);
    Purchase_Order.setFieldText('quantity_formattedValue', '1');
    Purchase_Order.setFieldText('rate_formattedValue', '1');
    Purchase_Order.setFieldText('amount_formattedValue', '1');
    Purchase_Order.setFieldText('inpt_taxcode', 'VAT_MX:UNDEF_MX');
    Purchase_Order.setFieldText('grossamt_formattedValue', '1');
    Purchase_Order.setFieldText('tax1amt_formattedValue', '0');
    Purchase_Order.setFieldText('expectedreceiptdate', '24/6/2015');
            //var Purchase_Orderid =  1;//nlapiSubmitRecord( Purchase_Order , true, true);                   
            var submitRecord = nlapiSubmitRecord(Purchase_Order);//,true);
            nlapiLogExecution('DEBUG', 'submirRecord ' + submitRecord);
}
var mesg = new Object();
mesg.status = "OK";
mesg.message= nlobjAssistant.getAllFields();
return mesg;

}

Java中的函数代码为:

WebClient client = new WebClient(BrowserVersion.FIREFOX_31);
        client.getOptions().setJavaScriptEnabled(false);
        client.getOptions().setThrowExceptionOnScriptError(false);
        WebRequest requestSettings = new WebRequest(new URL(url),HttpMethod.POST);
        requestSettings.setAdditionalHeader("Host", "rest.na1.netsuite.com");
        requestSettings.setAdditionalHeader("User-Agent", "SuiteScript-Call");
        requestSettings.setAdditionalHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
        requestSettings.setAdditionalHeader("Accept-Language", " es-cl,es;q=0.8,en-us;q=0.5,en;q=0.3");
        requestSettings.setAdditionalHeader("Accept-Encoding", "gzip, deflate");
        requestSettings.setAdditionalHeader("Content-Type", "application/json");
        requestSettings.setAdditionalHeader("Pragma", "no-cache");
        requestSettings.setAdditionalHeader("Cache-Control", "no-cache");
        requestSettings.setAdditionalHeader("Referer", "http://localhost:8084");
        requestSettings.setAdditionalHeader("Cookie", "");
        requestSettings.setAdditionalHeader("Connection", "keep-alive");
        requestSettings.setAdditionalHeader("Authorization", "NLAuth nlauth_account=" + account + ", nlauth_email=" + mail + ", nlauth_signature=" + pass + ", nlauth_role=" + role + "");
        Gson gson = new Gson();
        //objeto llenado estaticamente de forma momentanea, se debe leer desde archivo externo                    
        Purchase_Order purchaseOrder = new Purchase_Order("25/06/2015","formTest","vendorTest","CurrencyTest","itemTest");
        String cuerpo = gson.toJson(purchaseOrder);
        System.out.println(cuerpo);

//设置请求参数requestSettings.setRequestBody (cuerpo);

        Page page = client.getPage(requestSettings);
        WebResponse response = page.getWebResponse();
        String json = response.getContentAsString();
        System.out.println(json);

有了这个javascript函数,你应该为我创建一个记录采购订单,但我找不到错误和解决方案,如果有人能帮助我,我会非常感激。PS:如果你要创建一个自定义表单可以告诉我怎么做?谢谢!

以下是一些要点:

当您的错误消息显示Please enter value (s) for: Vendor时,您错过了供应商字段的值,这是强制性的。在你的代码块,你传递错误的internalid值的供应商。你应该用entity而不是vendor

 Purchase_Order.setFieldValue('entity', Vendor); // where vendor is the internal id of the vendor record

设置自定义表单,可以使用

Purchase_Order.setFieldValue('customform', Form); // where Form is the id of the custom form

我还注意到你在采购订单中设置了一些值,我怀疑这是一种自定义值。如果是这种情况,那么您的自定义字段内部id应该以custbody为前缀。对于所有的标准字段内部id,您可以参考套件脚本记录浏览器。

相关内容

  • 没有找到相关文章

最新更新