gpt4 book ai didi

javascript - 在搜索到的最大序列号上加一

转载 作者:行者123 更新时间:2023-11-28 03:48:48 27 4
gpt4 key购买 nike

当序列号存在时,不执行任何操作;当序列号不存在时,搜索我们的数据库并将找到的最高序列号加一。我的代码没有添加一个。所以我一直得到相同的号码。 当序列号存在时,不执行任何操作;当序列号不存在时,搜索我们的数据库并将找到的最高序列号加一。我的代码没有添加一个。所以我一直得到相同的号码。

 // Is there a current serial number? If yes, use that sequence number else generate a new one.
var currentSerialNumber = nlapiGetFieldValue('custrecordbcs_arm_serial');
if (currentSerialNumber == null || currentSerialNumber == '')
{
nlapiLogExecution('DEBUG','NUmber of REcords3','here');
// ok - serial number is blank - let'g get a new sequence number
var SerialNo = nextSerialNo();

} else {
nlapiLogExecution('DEBUG','NUmber of REcords4','here');
// a serial number has already been issued - use it's sequence number
var SerialNo = currentSerialNumber.substring(10,14);

}




var modulecode = 'ARM';
var tmpSubscription = nlapiGetFieldValue('custrecordbcs_arm_c');
if (tmpSubscription == 'T') {
var subscription = true;
} else {
var subscription = false;
}
if (subscription == true) {
isSubscription = true;
serialtype = 'C';
} else {
isSubscription = false;
}
// calculating the final serial number
var finalserialnumber = (serialtype + HashKey + months + year + modulecode + SerialNo);
nlapiLogExecution('DEBUG','Final Serial',finalserialnumber);
// calculating the unlock key
var unlockkey = Getunlockforuser(companyname, finalserialnumber, isSubscription);
nlapiLogExecution('DEBUG','Unlock',unlockkey);
// this is placing the serial number and unlock key into the fields in netsuite.
nlapiSetFieldValue('custrecordbcs_arm_unlock',unlockkey);
nlapiSetFieldValue('custrecordbcs_arm_serial',finalserialnumber);
//

}




function nextSerialNo(){
// this function will calculate the serial number based off the highest record found in netsuite
nlapiLogExecution('DEBUG','NUmber of REcords1','here');
var filters = new Array();
filters[0] = new nlobjSearchFilter('isinactive',null,'is','F');
filters[1] = new nlobjSearchFilter('custrecord_bcs_cm_lapse',null,'is','F');
filters[2] = new nlobjSearchFilter('custrecordbcs_arm_serial',null,'isnotempty','F');

var columns = new Array();
columns[0] = new nlobjSearchColumn('internalid');
columns[1] = new nlobjSearchColumn('custrecordbcs_arm_serial');


var highNumber = 0;
var allUnlockKeys = nlapiSearchRecord('customrecord_bcs_contracts',null,filters,columns);


nlapiLogExecution('DEBUG','NUmber of REcords','null');

for (var i=0; allUnlockKeys != null && i < allUnlockKeys.length; i++)
{

var x = Number(allUnlockKeys[i].getValue(columns[1]).substring(10,14));
nlapiLogExecution('DEBUG','value of x',x.toString());
if (x > highNumber){
highNumber = x+1;
}
}

return padstring(highNumber,4);
}

最佳答案

首先,我建议迁移到 SuiteScript 2.0。话虽如此,这是一个快速而肮脏的尝试来回答你的问题,因为我不能 100% 确定你的数据是什么样的。我还将该数字解析为整数以确保它是一个数字。我也会在生产版本中添加一些测试。希望这有助于为您指明正确的方向。

简而言之,使用您的搜索,但按您要添加到的字段降序排序(因此您的第一个结果应该是当前最高的)。您还可以在已保存的搜索中执行此操作,然后加载该搜索,仅查看第一行。

require(['N/search'],function(search){
function nextSerialNo(){
log.debug('NUmber of REcords1','here');
var highNumber=0;
var resultArray=[];
var contractlineSearchObj=search.create({
type:"customrecord_bcs_contracts",
filters:[["isinactive","is",false],"and",["custrecord_bcs_cm_lapse","is",false],"and",["custrecordbcs_arm_serial","isnotempty"]],
columns:[
search.createColumn({
name:"internalid",
}),
search.createColumn({
name:"custrecordbcs_arm_serial",
sort:search.Sort.DESC
})
]
}).run().each(function(result){
log.debug('result: ',JSON.stringify(result));
var highNumber=result.getValue({name:'custrecordbcs_arm_serial'});
log.debug('highNumber1: ',JSON.stringify(highNumber));

var highNumber=highNumber.toString().substring(2,3);
log.debug('highNumber2: ',JSON.stringify(highNumber));

var highNumber=parseInt(highNumber)+1;
log.debug('highNumber3: ',JSON.stringify(highNumber));
return false
});

return padstring(highNumber,4);
}

nextSerialNo()
});

此外,这是 2.0 模块的主页:SuiteScript 2.0 Modules

关于javascript - 在搜索到的最大序列号上加一,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48213305/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com