/**
* @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 内),此后我将创建此销售订单的文件。想法结束这里是将上次运行记录的创建日期与当前日期时间进行比较,然后将此当前时间与下一次运行的下一个当前日期时间进行比较,但问题是我无法比较日期的格式,即 new Date() 与我试图在保存的搜索创建中使用的日期。**