Reputation: 47
I am having trouble in rescheduling a scheduled script. I have created script parameter 'last_processed_record_id'. I am not aware of how to pass that lastprocessed id in script parameter and run script from where it left.
In my scheduled script, I am processing Invoice saved search results.Please advice!
define(['N/search', 'N/runtime', 'N/record', 'N/task', 'N/file', 'N/format',
'SuiteScripts/abc/Lib/abc_lib'], function(search, runtime, record, task, file,
format, lib) {
function execute(context) {
processSearchResults();
var usage= runtime.getCurrentScript();
log.debug('Remaining governance units: ' + usage.getRemainingUsage());
}
//This function fetches saved search data and creates journal entry record
function processSearchResults(results, scriptid) {
results.forEach(function(result) {
var recId= result.getValue({
name: "internalid", label: "Internal ID"
});
var amount = result.getValue({
name: "amount",
label: "amount"
});
})
}
//This function updates created jounal entries on invoice line level custom JE
field on invoice.
function updateInvoice() {
}
return {
execute: execute
}
})
Upvotes: 0
Views: 52
Reputation: 21
To get last processed record ID for next runs of a scheduled script, follow these steps:
Add a parameter to the script record to store the record ID:
Navigate to the Script Record.
Go to the Parameters subtab.
Click the New Parameter button to create a new parameter.
Example Screenshot for adding a parameter:
.
You need to handle the parameter in two places:
params
object in the task.create
API to pass the parameter value when scheduling the script for its next run.var scriptTask = task.create({
taskType: task.TaskType.SCHEDULED_SCRIPT
});
scriptTask.scriptId = 'customscript_your_script_id';
scriptTask.deploymentId = 'customdeploy_your_deployment_id';
scriptTask.params = {
custscript_last_processed_record_id: lastProcessedId // Replace with your parameter ID and value
};
scriptTask.submit();
ScriptObject.getParameter
to fetch the parameter value. var lastProcessedId = runtime.getCurrentScript().getParameter({
name: 'custscript_last_processed_record_id' // Replace with your parameter ID
});
log.debug('Last Processed Record ID', lastProcessedId);
By following these steps, you can store the last processed record ID
Upvotes: 2