Marvin
07/15/2022, 3:27 AM// loop through the JSON files from Suitelet
file_results_mapped.some(file_result => {
// parse settings from a string into a javascript object
const file_updates = JSON.parse(settings_file.getContents());
// loop through the selected_transactions
file_updates.selected_transactions.some(transaction => {
// ... process transaction updates
if (runtime.getCurrentScript().getRemainingUsage() < 500) {
governance_triggered = true;
log.audit({
title: 'STOPPING_DUE_TO_GOVERNANCE',
details: {
getRemainingUsage: runtime.getCurrentScript().getRemainingUsage()
}
});
return true; // breaks internal loop
}
});
// ... send email update about processed transactions
if (governance_triggered === true && file_updates.selected_transactions.length > 0) {
const file_object = file.create({
name: settings_file.name,
fileType: file.Type.JSON,
folder: settings_file.folder,
contents: JSON.stringify(file_updates),
encoding: file.Encoding.UTF8
});
file_object.save();
log.audit({
title: "FILE_UPDATED",
details: {
name: settings_file.name,
}
});
} else {
// delete the file so it doesn't get processed again
file.delete({
id: file_result.id
});
log.audit({
title: "FILE_DELETED",
details: {
id: file_result.id
}
});
}
return governance_triggered;
});
I can see it log STOPPING_DUE_TO_GOVERNANCE and then FILE_UPDATED.
The last line return governance_triggered;
should break from the .some
loop and end the script.Marvin
07/15/2022, 4:57 AMSandii
07/15/2022, 3:24 PMMarvin
07/15/2022, 5:40 PM