Hi all, is that possible to run a script automatic...
# suitescript
n
Hi all, is that possible to run a script automatically when a csv import is done? thanks
r
What type of script are you looking at? I know User Event scripts deployed on the record being imported will trigger as long as you have the "RUN SERVER SUITESCRIPT AND TRIGGER WORKFLOWS" options checked in the CSV Import preferences
n
yes but I want to run a mass update or a scheduled script when all records are imported. I had a thought on UE but UE will not know whether it's the last record
r
In that case, I dont think that is possible
n
or, should I run the csv import using a scheduled script and get the task status constantly till it's complete?
r
That should work but I have not tried that approach
n
thanks, Gerrom! btw does it happen to you to know some ways to delay a script for seconds or minutes?
a
@nzy Your best bet is create a Suitelet which accept a CSV file and offload the record processing to a map reduce and from the summarize stage of the map reduce (when it finish) you can do what you need.
👍 2
@nzy About the delay in script, there is no official or probably possible way for server side scripts…
n
thanks, @alien4u that is very helpful for me.
m
@nzy what happened to this page 😜
WRT your actual question I remembered there was something in the release notes about setting a script to run after a task is complete but it seems like that is only for M/R and search tasks
n
LOL honestly i haven't got a chance to validate if that is a legit solution which works in long terms
m
It's definitely very abusive
🤣 1
n
I think i will try suitelet + MR, this should be a very elegant solution
m
Yeah agreed
z
We want a script to run after the CSV import. It doesn't need to run immediately after. The CSV import doesn't even need to "know" about it. We need a sequence of events, but we don't actually need synchronous execution. Generally speaking, when I think I need a script to "sleep" or "wait" in order to make things happen in sequence, what I really need is a shift in perspective away from the model of synchronous processing. I can play to the strengths of JavaScript and the SuiteScript platform with event-based architecture (Observer pattern), Promises, etc., and other techniques that manage tasks asynchronously and/or build sequences of tasks based on stateful change (without worrying about when or how long until the change happens).
One idea for a solution: Use a Custom Record for CSV Import Process Control. Basic attributes would include process name, script, deployment, start time, process status, end time, etc., as well as fields that capture information sufficient to describe and track the post-import tasks.
Create a Scheduled Script or Map Reduce script to "poll" CSV imports as well as process control records at a given time interval - e.g., every hour, examine the result of a saved search that selects process control records where the CSV Import is complete and the post-import task is in a "not started" status. For each of these, the script triggers the appropriate post-import tasks.
Note: the custom record could describe a type or pattern of CSV Import that occurs regularly ("look for imports that fit these parameters and then do x, y, and z") or it could be designed to refer to a specific CSV import - or you could design a solution to utilize both kinds of information. It would be simpler to have a solution that looks for a CSV import task that fits a certain pattern and, if it finds a "recent" one that it doesn't recognize, it creates a process tracking record for it and, when the import is complete, oit "reacts" and fires off the post-import task (which it also tracks). That kind of architecture would save the user from having to do anything special every time he or she initiates a CSV import. The idea is to make the process asynchronous and idempotent by design.