0
/**
* @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() 与我试图在保存的搜索创建中使用的日期。**

4

1 回答 1

1

我的建议是在您的预定脚本上创建一个脚本参数,例如 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
    }
});
于 2020-03-10T04:04:44.227 回答