0

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

2015 年 8 月 3 日下午 2:49:00 com.gargoylesoftware.htmlunit.WebClient printContentIfNecessary INFO: {"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:如果你要创建一个定制的表格能告诉我怎么做吗?谢谢!

4

1 回答 1

2

这里有几点:

正如您的错误消息所说Please enter value (s) for: Vendor,您缺少 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,您可以参考套件脚本记录浏览器。

于 2015-08-04T13:33:55.573 回答