Anyone know of a "non-hacky" way to add a X minute...
# suitescript
e
Anyone know of a "non-hacky" way to add a X minute delay before starting a map/reduce script? Scenario: I'm using a script to mass receive some POs that are on Inbound Shipments. But doing so just starts a "background process" (this is native NetSuite functionality) that actually creates the Item Receipts, and then links them to the Inbound Shipment. So there is a delay between when Script 1 runs and when I want Script 2 (Map/Reduce) to run.
e
Can you say more about the Scripts involved here? Script Types, entry points, etc
e
Sure thing- I have a Suitelet script that intake a CSV that the user uploads. That suitelet loads, fills outs some data, and saves a "receiveinboundshipment" record. (This is the equivalent of clicking the "Receive" button from an Inbound Shipment record, filling out the Qtys/Inventory Details, and saving it) When this record is saved, a background process starts (in the UI, NetSuite displays a screen that shows that Item Receipts are being created and shows the status - once done, it shows links to the Item Receipts that were created) I essentially need to run some logic on those Item Receipts when they get created, however... I added a UE script to the Item Receipt and tried using .getValue('inboundshipment') - but it doesn't return anything in the before or after submit. So now my approach is... create a Map/Reduce to find the Item Receipts that have the "Inbound Shipment" field filled in and run the logic on them. But one missing piece is that there is data in the Suitelet script that I need to pass to the Map/Reduce script. So I was hoping to be able to task.create the Map/Reduce script so I could pass the data. But if I can it instantly from the Suitelet, the Item Receipt records won't be created yet. This is why I'm trying to add a delay.
I've considered just leaving the M/R script running every 15 mins, but the issue there is that a user could upload multiple CSVs to the Suitelet in a 15 min period, so the data I get from the Suitelet script (that is needed in the Map/Reduce) will be overwritten
e
I added a UE script to the Item Receipt and tried using .getValue('inboundshipment') - but it doesn't return anything in the before or after submit.
Unfortunate.
e
Right? I'm still confused as to how that's even possible...
inboundshipment
is blank when the IR is created (when the UE script is called), but when I open the record in the UI, the field is filled in. And if I load/save the record, then I can get the
inboundshipment
value, but it's not valuable at that point
I think I might need to use
N/cache
to pass the data from the Suitelet Script to the Map/Reduce script
e
There are a few fields that behave that way, where NS doesn't seem to populate them until after all the
afterSubmit
calls (e.g.
createdfrom
). It's maddening.
The Suitelet could write its data to a file, or to the cache, and the M/R could look for unprocessed files or in the cache. I tend to prefer files, only because of the indeterminate nature of the cache.
e
Yeah, I like that approach. I could just delete the file after I've processed it (or move it to a processed folder) from the Map/Reduce.
e
^ This is the way
n
@ericbirdsall Did you load the record in afterSubmit or did you use the newRecord object?
e
You nailed it @NickSuite . I was using newRecord and the value didnt show. But when I load the record, it does show!
e
Not ideal to double-load, but probably no less efficient than having to write/read files
n
I am glad it worked!
@erictgrubaugh I think that's how NS has designed it. Load the record if you need to access certain fields.
e
I can also get it from context.newRecord.fields.inboundshipmentvalue BUT only if I make a deep copy of context.newRecord (??) context.newRecord.fields returns nothing But JSON.parse(JSON.stringify(context.newRecord)).fields returns an object and there is a inboundshipmentvalue property (and value) This feels less reliable so I’m accepting the double load
e
In an
afterSubmit
, I'd expect all of the internal fields to have settled already. It's always puzzled me that most of them are settled, but a few are not.
n
Excatly. That's why we have to load.
e
I understand that's why we have to. My perspective is that we shouldn't have to.
2