Suitescript代码无故停止 [英] Suitescript Code stops for no apparent Reason
问题描述
我有以下代码,该代码执行搜索,然后停止.
I have the following code which executes a search, then just stops.
for (var i=1; i<=numberItems; i++ ) {
nlapiInsertLineItem(SUBLIST_Items,1);
var itemID = vendorItems[i].getId();
nlapiSetCurrentLineItemValue(SUBLIST_Items,'custrecordvpri_item',itemID );
var avgCost = Round(nlapiLookupField(itemType,itemID,'averagecost'),4);
var stdCost = Round(nlapiLookupField(itemType,itemID,'custitem_costrepl'),4);
var lastCost = Round(nlapiLookupField(itemType,itemID,'lastpurchaseprice'),4);
if (isNaN(avgCost)) { avgCost = '' };
if (isNaN(stdCost)) { stdCost = '' };
if (isNaN(lastCost)) { lastCost = '' };
nlapiSetCurrentLineItemValue(SUBLIST_Items,'custrecordvpri_costavg', avgCost );
nlapiSetCurrentLineItemValue(SUBLIST_Items,'custrecordvpri_costlast', lastCost );
nlapiSetCurrentLineItemValue(SUBLIST_Items,'custrecordvpri_coststd', stdCost );
nlapiSetCurrentLineItemValue(SUBLIST_Items,'custrecordvpri_vendorcurrency',vendorItems[i].getValue('vendorpricecurrency'));
nlapiSetCurrentLineItemValue(SUBLIST_Items,'custrecordvpri_currentprice',vendorItems[i].getValue('vendorcost'));
nlapiCommitLineItem(SUBLIST_Items);
}
所有这些都作为客户端脚本运行,由供应商记录上的按钮触发.
It is all running as a client script, triggered by a button on the supplier record.
此功能中有一些子功能(例如,搜索等).
There are some sub functions within this functon (ie. a search etc...).
我找不到代码停止的原因.
I cannot find a reason why the code would stop.
如果我注释掉"while"循环,它将执行新窗口等...并创建主记录(VprRecord),但没有子列表项.
if I comment out the "while" loop, it executes the new window etc... and the main record (VprRecord) is created, but with no sublist items.
我这里缺少什么吗?我不是一个经验丰富的JS程序员,但是这里面有基础.是否允许有限数量的嵌套函数或类似的东西?
Is there something I'm missing here?? I'm not an experienced JS programmer, but the basics are there. Is there a limited number of nested functions permitted or something like that?
我只有一个记录创建者,因此治理不应该成为问题.
I only have the one record creation, so governance shouldn't be an issue.
添加我的搜索功能以返回搜索结果对象:
Adding my search function which returns the search result object:
function getVendorItems(vendorid) {
try {
var filters = new Array();
var columns = new Array();
filters[0] = new nlobjSearchFilter('vendorcost', null, 'greaterthan', 0);
filters[1] = new nlobjSearchFilter('internalid', 'vendor', 'anyof', vendorid );
columns[0] = new nlobjSearchColumn('itemid');
columns[1] = new nlobjSearchColumn('entityid', 'vendor');
columns[2] = new nlobjSearchColumn('vendorcost');
columns[3] = new nlobjSearchColumn('vendorcode');
columns[4] = new nlobjSearchColumn('vendorpricecurrency');
//columns[5] = new nlobjSearchColumn('preferredvendor');
var searchresults = nlapiSearchRecord('item', null, filters, columns );
return searchresults;
} catch (err) { logError(err,'VPR_getVendorItems: (Vendor: '+vendorid+')' ) }
}
推荐答案
由于存在未处理的javascript错误,因此代码未执行.
The code does not execute because there are unhandled javascript errors.
将您的代码放入try catch块和控制台的错误日志中,例如:
try { ...} catch(e){console.dir(e);}
put your code in try catch block and on error log on console eg:
try { ...} catch(e){console.dir(e);}
通过F12使用浏览器的控制台查看错误
Use browser's console using F12 to see the error
此外,请确保您在searchResults
上以数组而不是nlobjSearchResult
Also, make sure that you operate on searchResults
as array not nlobjSearchResult
这篇关于Suitescript代码无故停止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!