gpt4 book ai didi

javascript - Netsuite 计划脚本保存的搜索

转载 作者:行者123 更新时间:2023-12-02 21:31:38 24 4
gpt4 key购买 nike

/**
* @NApiVersion 2.x
* @NScriptType ScheduledScript
* @NModuleScope SameAccount
*/
define(['N/search','N/record','N/file'],

function(search,record,file) {

/**
* Definition of the Scheduled script trigger point.
*
*@param {search} search
*@param {record} record
*@param {file} file
* @param {Object} scriptContext
* @param {string} scriptContext.type - The context in which the script is executed. It is one of the values from the scriptContext.InvocationType enum.
* @Since 2015.2
*/
function execute(context) {

var currentdate=new Date().getTime();
var arr=[];
arr.push(currentdate);


for(i in arr){
if(arr.length==1){
var cmpdate=arr[i];
}
var cmpdate=arr[i--];
}

var sosearch=search.create({type:search.Type.TRANSACTION,
filters:[
['type',search.Operator.ANYOF,'SalesOrd'],'and',
['mainline',search.Operator.IS,true],'and',
['formuladate',search.Operator.AFTER,cmpdate]
],
columns:['salesoreder']

});

var searchresult=sosearch.run().each(function(result) {
var soid= result.getValue({
name: 'internalid'
});
});

for(r in searchresult){
var sorec=record.load({type:'salesorder',id:searchresult[r]});
var myfile=file.create({name:maqsofile,fileType:file.Type.CSV,contents:sorec})
myfile.folder=520;
myfile.save();
}
}
return {
execute: execute
};

});

**我正在尝试执行保存的搜索,以便每当触发脚本时我都会获取在该时间段内(例如:每 30m 内)创建的销售订单,此后我将创建该销售订单的文件。这里的想法是将上次运行记录的创建日期与当前日期时间进行比较,然后将当前时间与下次运行的下一个当前日期时间进行比较,但问题是 iam 无法比较日期格式,即新日期() 与我尝试在保存的搜索创建中使用的日期。 **

最佳答案

我的建议是在计划的脚本上创建一个脚本参数,例如custscript_last_search_thru_date。然后在搜索运行后更新参数,以便可以将其用作下次脚本运行的开始日期。

var searchStartDate = runtime.getCurrentScript().getParameter({name: 'custscript_last_search_thru_date'});
var searchEndDate=new Date();

filters.push(search.createFilter({
name: 'datecreated',
operator: search.Operator.AFTER,
values: searchStartDate.getTime()
}));

filters.push(search.createFilter({
name: 'datecreated',
operator: search.Operator.ONORBEFORE,
values: searchEndDate.getTime()
}));

// Run search and do stuff

record.submitFields({
type: 'scriptdeployment',
id: deploymentId,
values: {
custscript_last_search_thru_date : searchEndDate
}
});

关于javascript - Netsuite 计划脚本保存的搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60610011/

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