Hi there, I need to create two different records (...
# suitescript
n
Hi there, I need to create two different records (Record 2 and 3) in waterfall after saving another record (record 1), knowing that to create record 2 and record 3 I need to get values from record 1 plus some system variables. Also record 1 is usually created in batch via CSV upload... Performance wise, is it better to simply use a basic UE after submit or should I trigger a M/R script? Thanks a lot πŸ˜‡
b
map/reduce is generally more performant than a user event script
you would only want to use the user event script if its required that record 2 and 3 need to be created right after 1
z
MR faster than UE??????? but, when that's saying @battk, I really want to hear explanation
b
the general weakness of the user event script is that its synchronous, record 1 wont finish saving until record 2 and 3 are done
if you want record 1 to be saved as quickly as possible, and can wait for 2 and 3 later, then you dont want to do the extra work
z
Honestly, i don't understand dilemma UE vs MR in rhe question... I would if question was User event or Scheduled task..
n
I need the waterfall effect with after submit 1, create 2 with data from record 1, when 2 is created, create 3 with data from record 1 and record 2. The dilemma is that I want to make sure that an UE won't take too long to save record 1 and won't create issues during CSV imports of record 1. If scheduled tasks is better, I don't mind, either.
z
Keep in mind:... UserEvent will be triggered only for Record1. If you have UE for both Record1 and Record2, and expect to both going to be triggered in chain, unfortunately won't.
Next, CSV import can be processed in two different ways : with or without executing server side scripts (User events)
Next: It is not possible to submit the same deployment for MR or Scheduled task while previous still running... that could be important detail in case if you opted for using either MR or Scheduled task for creating record2-3
n
Thanks for the extra pieces of info. I will need to trigger the script when creating record 1 via CSV imports, this is why I was afraid of performance or concurrency limit. I guess I'll take a shot with a basic UE After Submit and see. What would you recommend for making sure I can create record 3 when record 2 is created? Saving the internal ID of record 2 and do a if statement to make sure it exists?
l
Would be great to hear your results, I think the MR approach will be more effective, I would try to implement a MR to create the 1st and 2nd record and the 3rd as a UE after submit....πŸ€·β€β™‚οΈ
n
I will, next month πŸ˜‰ Record 1 is always created in UI or CSV. It’s the creation of record 1 that is triggering the creation of record 2.
z
It's doesn't make sense to create ONE MR task for each USEREVENT, and there create one record2 and one record3... MR is efficient for MASS creating/updating records... It is really hard (for me, I don't know for others) to handle concurrent execution of ONE task with multiple deployments... In theory, you can have multiple deployments and then submit more than once the same task (MR or Scheduled)... and what if all deployments are active... and.. and.. Generally, best practices for writing UE scripts are : try to minimize data manipulation and provide the response as as fast as possible, especially in UI context... and experts advise you to use Scheduled task from UE CSV import context ... from my point of view, I would opt for compact UE, all records being created inside UE. Why? Let's simulate You have a 10000 records of record1 type... NetSuite import started, and 1,2,3,4th... row going to be inserted in database.. If you want to create MR even ScheduledTask every time an record is inserted...really not possible! Just remind you MR and Scheduled Task are asynchronous!!! The internal scheduler might decide to put your MR tasks on the lowest priority and CSV import can insert next row before "userevent" for previous even being started... I didn't mention debugging and logging 😁... If any error raise in MR task, it is not linked with originally UE from record1... This is just my vision of possible solution and issues... Playing with different kind of tasks and scripts are mandatory... Try it all!
n
Thanks Zoran. Your input is greatly appreciated
b
zoran is talking about using N/task in a user event script to create tasks as records 1s are created
the more usual case for map/reduce is to have it run on a schedule
and then do a search/query for record 1 that need to have record 2/3 created and do your logic on each one
πŸ’― 1
it really depends on how quickly you want your record 2/3s created
another technique you can use if these are custom records is the parent/child relationship
The SAFE guide describes how to use parent/child relationships for transactional purposes in section 2.3.4
πŸ‘ 1
you wouldnt be able to get it to go to 3 levels, but you could do 2
n
What do you guys think about using premises?
b
use SuiteScript 2.x Promise APIs to determine if the apis you are using support Promises
if you intend to use Promises, make sure you have a solid Error handling strategy, there is no global Promise rejection handler in suitescript
thanks 1