Hi all
I am trying to execute a script in NetSuite after a flow completes. I have been trying to use a postSubmit hook but get the following error: "invalid postSubmit hook response: expecting canonical data response with same size"
Very simplistically, the flow in question looks up data in our supplier API (http) and writes this to a custom record in NetSuite (where each record is the suppliers ItemCode). This data includes stock availability quantities, future stock-in dates, if the item can be exported to the UK (we deal with plants so this can change for each item, ie it is not a constant). After the data has been refreshed, I want to execute a script that determines if we can offer the item for sale on our website, estimated lead time and toggle on/off various field settings accordingly. I want to execute this script as soon as the flow has completed rather than running it on a scheduled basis.
Here's the flow
I have tried writing the script as a Restlet, map/reduce and also scheduled type but with no schedule (my understanding being that we should still be able to call this to execute on demand)
Here is a simplified version of the type of script I need to execute
/**
* @NApiVersion 2.x
* @NScriptType ScheduledScript
*/
define(['N/search', 'N/record', 'N/log'], function(search, record, log) {
function execute(context) {
try {
var searchId = '4815';
var savedSearch = search.load({
id: searchId
});
var searchResultCount = 0;
savedSearch.run().each(function(result) {
try {
var itemId = result.id;
// Load the item record
var itemRecord = record.load({
type: record.Type.INVENTORY_ITEM,
id: itemId,
isDynamic: true
});
// Set the custom field to true
itemRecord.setValue({
fieldId: 'custitem_celigo_shopify_enable_out_sto',
value: true
});
itemRecord.save();
searchResultCount++;
} catch (e) {
log.error('Error updating item', 'Item ID: ' + itemId + ', Error: ' + e.message);
}
return true;
});
log.audit('Scheduled Script Execution Completed', 'Updated ' + searchResultCount + ' items.');
} catch (e) {
log.error('Error executing scheduled script', e.message);
}
}
return {
execute: execute
};
});
I am therefore looking for a way to simply trigger this script to run after the flow completes. I do not need it to reference back to any of the records in the flow, ie I don't think I need a response, but suspect Celigo is looking for one and hence the error message?
Any input gratefully received.
Tagging @lakhanbhagnani as requested
Thanks all - Sandra