Suitescript 代码无故停止
Suitescript Code stops for no apparent Reason
我有以下执行搜索的代码,然后就停止了。
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);
}
都是运行客户端脚本,由供应商记录上的按钮触发。
此功能中有一些子功能(即搜索等...)。
我找不到代码停止的原因。
如果我注释掉 "while" 循环,它会执行新的 window 等...并创建主记录 (VprRecord),但没有子列表项。
我在这里遗漏了什么吗??我不是一个经验丰富的 JS 程序员,但基础知识在那里。是否允许有限数量的嵌套函数或类似的东西?
我只有一个记录创建,所以管理应该不是问题。
添加我的搜索功能,returns 搜索结果对象:
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 个错误。
将您的代码放入 try catch 块和控制台的错误日志中,例如:
try { ...} catch(e){console.dir(e);}
使用 F12 使用浏览器控制台查看错误
此外,请确保您对 searchResults
作为数组而不是 nlobjSearchResult
进行操作
我有以下执行搜索的代码,然后就停止了。
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);
}
都是运行客户端脚本,由供应商记录上的按钮触发。
此功能中有一些子功能(即搜索等...)。
我找不到代码停止的原因。
如果我注释掉 "while" 循环,它会执行新的 window 等...并创建主记录 (VprRecord),但没有子列表项。
我在这里遗漏了什么吗??我不是一个经验丰富的 JS 程序员,但基础知识在那里。是否允许有限数量的嵌套函数或类似的东西?
我只有一个记录创建,所以管理应该不是问题。
添加我的搜索功能,returns 搜索结果对象:
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 个错误。
将您的代码放入 try catch 块和控制台的错误日志中,例如:
try { ...} catch(e){console.dir(e);}
使用 F12 使用浏览器控制台查看错误
此外,请确保您对 searchResults
作为数组而不是 nlobjSearchResult