The following code snippet illustrates how to equally divide the search results of a saved search between several deployments of a script that are executing at the same time:
//create a filter array
var filters = new Array();
//set filter depending on the deployment instance that is executing
if(deployId == 'customdeploy_auto_item_fulfillment_asc'){
filter[0] = new nlobjSearchFilter('formulanumeric',null,'equalto','0');
filter[0].setFormula('MOD({internalid},4)');
}
else if (deployId == 'customdeploy_auto_item_fulfillment_desc'){
filter[0] = new nlobjSearchFilter('formulanumeric',null,'equalto','1');
filter[0].setFormula('MOD({internalid},4)');
}
else if (deployId == 'customdeploy_auto_item_fulfillment_q3'){
filter[0] = new nlobjSearchFilter('formulanumeric',null,'equalto','2');
filter[0].setFormula('MOD({internalid},4)');
}
else if (deployId == 'customdeploy_auto_item_fulfillment_q4'){
filter[0] = new nlobjSearchFilter('formulanumeric',null,'equalto','3');
filter[0].setFormula('MOD({internalid},4)');
}
//execute search
var searchresults = nlapiSearchRecord('salesorder', 1541 , filter, null);
Saturday, January 5, 2019
Equally divide the results of a saved search via SuiteScript
Use case: Customer has a scheduled script with multiple deployments running simultaneously on different queues. They need the results of the saved search to be equally divided across each script deployment.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment