NetSuite/Suitescript - 为什么此验证字段脚本会进入无限循环? [英] NetSuite / Suitescript - Why does this Validate Field script enter an infinite loop?
问题描述
我的脚本进入无限循环,我不知道为什么.我在验证字段上运行这个,如果另一个供应商账单存在相同的参考号,我会阻止对该字段的更改,迫使用户将参考号"更改为唯一的.这是我的代码:
My script is entering into an infinite loop and I have no idea why. I am running this on validate field and I am preventing a change to the field if another vendor bill exists with the same reference number, forcing the user to change the "Reference Number" to be unique. Here is my code:
function validateField(type, name) {
if (uniqueReferenceNum(type, name) === false) {
return false;
}
return true;
}
function uniqueReferenceNum(type, name) {
if (name !== 'tranid') {
return true;
}
var tranID = nlapiGetFieldValue('tranid');
var vendor = nlapiGetFieldValue('entity');
var vendorName = nlapiGetFieldText('entity');
var filters = new Array();
var columns = new Array();
filters[0] = new nlobjSearchFilter('entity', null, 'is', vendor);
filters[1] = new nlobjSearchFilter('tranid', null, 'is', tranID);
filters[2] = new nlobjSearchFilter('mainline', null, 'is', 'T');
columns[0] = new nlobjSearchColumn('internalid');
results = nlapiSearchRecord('vendorbill', null, filters, columns);
if (!results) {
return true;
}
alert("There is already a vendor bill with reference # " + tranID + " for " + vendorName + ". Please verify and change the reference number before continuing.");
return false;
}
推荐答案
对于那些仍然面临这个问题的人,您可以将有问题的字段 - 在这种情况下,Reference Number
- 设置为 'falsy' 值,例如空字符串.只有在检查字段包含真实"值后才返回 false
.然后向用户显示alert
或dialog
.这应该会打破验证循环.
For those still facing this issue, you can set the field in question - in this case, Reference Number
- to a 'falsy' value such as an empty string. Only return false
after checking that the field contains a 'truthy' value. Then display the alert
or dialog
to the user. This should break the validation loop.
这篇关于NetSuite/Suitescript - 为什么此验证字段脚本会进入无限循环?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!