we are refactoring some of our scripts and we want...
# suitescript
s
we are refactoring some of our scripts and we want the code in an after-submit should only run after a map-reduce task finishes , is this possible?
e
The after-submit function of a record will always run immediately after the record is saved to database. It will not be tied to the completion of the map-reduce job. What is the use-case for wanting that?
s
correct, I have an after-submit on Transfer Order that creates item fulfillment however we have assembly that need tob e build before the item fulfillment
w
have the map-reduce script check a box on the record and then run the afterSubmit only if that box is checked?
e
You can do this via configuration at the Script Deployment level by adjusting the Context Filtering on the Deployment record or in code via the
N/runtime
module's executionContext property
but you can't tie it specifically to the end of the M/R
w
(or a specific M/R)
e
You could use
N/runtime.Script
to detect a specific M/R
If the logic needs to be tied to the end of a specific M/R, then my question would be why is it in a User Event instead?
s
the map-reduce is building the assembly not tied to the transfer order record
w
can you not check in the after submit if the assembly has been built or not before fulfilling it? (I don't know much about assemblies)
s
so the transfer order is created via external api ---> Also a task for map reduce is created via reslet to trigger map reduce task
what I want to do is that after submitting the transfer order, first call the map-reduce task and then when it finishes like waiting for a promise then call the next function to create and item fulfillment
m
Sounds like this would be a use case for
.addInboundDependency()
option when triggering the Map/Reduce, but unfortunately, that's only available to search-type tasks. I wonder if you add multiple dependencies do they run in series or parallel. If the former, you could hack this by creating a dummy search task, and set your M/R and then the second script to create the IF as dependencies
b
i personally say use the logic from the after submit in the map/reduce script instead so you can make it run after the creation of the assembly record
if you really need it to run after the entire map/reduce, just make another map/reduce to create the item fulfillments and task it to run in the summarize phase of the original one
s
can i just move the logic from the after submit to summarize of the map/reduce ?
b
unlikely unless you are misusing the map/reduce script
map/reduce typically are used for bulk processing and you dont want to do any bulk in summarize or getInputData