/ *** @NApiVersion 2.x* @NScriptType ScheduledScript* @NModuleScope SameAccount* /define([['N / search','N / record','N / 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内)之后创建的销售订单。 order。此处的想法是将上次运行记录的创建日期与当前日期时间进行比较,然后将该当前时间与下一次运行的下一个当前日期时间进行比较,但是问题是我无法比较日期格式,即新的Date()以及要在保存的搜索创建中尝试使用的日期。 **
我的建议是在预定的脚本上创建脚本参数,例如custscript_last_search_thru_date。然后,在运行搜索之后更新参数,以便在下次脚本运行时将其用作开始日期。
var searchStartDate = runtime.getCurrentScript().getParameter({name: 'custscript_last_search_thru_date'});
var searchEndDate=new Date().getTime();
filters.push(search.createFilter({
name: 'datecreated',
operator: search.Operator.AFTER,
values: searchStartDate
}));
filters.push(search.createFilter({
name: 'datecreated',
operator: search.Operator.ONORBEFORE,
values: searchEndDate
}));
// Run search and do stuff
record.submitFields({
type: 'scriptdeployment',
id: deploymentId,
values: {
custscript_last_search_thru_date : searchEndDate
}
});