编辑:我已经编辑了实际数字并用伪咒语替换了它们,因为我被告知共享性能数据违反了 Netsuite 的 TOS。
我正在使用 Restlet 将我们的会计系统与 NetSuite 集成,总体来说,除了性能方面的明显例外之外,它运行得非常好。从性能角度来看,我发现 nlapiLoadRecord 是撒旦自己的孩子,因此我尽可能避免使用它,而倾向于搜索 api,现在我的读取 Restlet 非常敏捷。然而,每当我要求 Restlet 写任何东西时,它都像困在冷焦油中的乌龟一样慢。我通常在两者之间分析 nlapiSubmitRecord 本身SLOW and 真的太慢了秒。这对我来说似乎很疯狂。如果 NetSuite 的写入性能总是这么差,那么没有人会使用 NetSuite。我将在下面提供一些代码示例。如果有任何有关加快 NetSuite Restlet 写入性能的提示,我们将不胜感激。
在第一个中,receivedInvoice 是传入数据,findCurrencyCode 和 findCustomerByCustomerNumber 是执行这些操作的性能良好的函数。我刚刚以几乎令人难以置信的速度计时缓慢的圣猴一张包含一个行项目的简单发票需要几秒钟,几乎所有时间都在我等待 nlapiSubmitRecord 完成时流逝。
var createdInvoice = nlapiCreateRecord('invoice');
createdInvoice.setFieldValue('customform', Number(receivedInvoice.transactionType));
createdInvoice.setFieldValue('memo', receivedInvoice.message);
createdInvoice.setFieldValue('duedate', receivedInvoice.dateDue);
createdInvoice.setFieldValue('currency', findCurrencyCode(receivedInvoice.currencyUnit));
createdInvoice.setFieldValue('location', Number(receivedInvoice.location));
createdInvoice.setFieldValue('postingperiod', findPostingPeriod(receivedInvoice.datePosted));
var customer = findCustomerByCustomerNumber(receivedInvoice.customerNumber);
createdInvoice.setFieldValue('entity', customer.customerId );
createdInvoice.setFieldValue('custbody_end_user', customer.customerId );
createdInvoice.setFieldValue('department', customer.departmentId);
var itemCount = receivedInvoice.items.length;
for(var i = 0; i < itemCount; i++)
{
createdInvoice.selectNewLineItem('item');
createdInvoice.setCurrentLineItemValue('item', 'item',receivedInvoice.items[i].item);
createdInvoice.setCurrentLineItemValue('item', 'quantity', receivedInvoice.items[i].quantity);
createdInvoice.setCurrentLineItemValue('item', 'rate',receivedInvoice.items[i].price);
createdInvoice.setCurrentLineItemValue('item', 'custcol_list_rate',receivedInvoice.items[i].price);
createdInvoice.setCurrentLineItemValue('item', 'amount',receivedInvoice.items[i].totalAmount);
createdInvoice.setCurrentLineItemValue('item', 'description',receivedInvoice.items[i].description);
createdInvoice.commitLineItem('item');
}
var recordNumber = nlapiSubmitRecord(createdInvoice,false,true);
在这个中,我认为我通过以动态模式打开记录来犯下性能异端,但我不确定如何获取可能的行项目。只需在动态模式下打开一个新记录,时间大约为SLOW秒。同样,提交是花费最多时间的地方(通常在噢,亲爱的可怕的母亲秒),尽管这会占用相当多的时间,因为我弄乱了行项目,这又可能是因为我在动态模式下打开了记录。
var customerPayment = nlapiCreateRecord('customerpayment',{recordmode: 'dynamic'});
customerPayment.setFieldValue('customer', parseInt(customerId));
customerPayment.setFieldValue('payment', paymentAmount);
customerPayment.setFieldValue('paymentmethod', paymentMethod);
customerPayment.setFieldValue('checknum', transactionId);
customerPayment.setFieldValue('currency', currency);
customerPayment.setFieldValue('account', account);
var applyCount = customerPayment.getLineItemCount('apply');
if(applyCount>0)
{
for(var i=1;i<=applyCount;i++)
{
var thisInvoice = customerPayment.getLineItemValue('apply','refnum',i);
if(thisInvoice == invoiceToPay)
{
customerPayment.selectLineItem('apply', i);
customerPayment.setCurrentLineItemValue('apply','apply','T');
customerPayment.setCurrentLineItemValue('apply', 'amount',paymentAmount);
customerPayment.commitLineItem('apply');
}
}
}
nlapiSubmitRecord(customerPayment,false,true);