What's the efficient way to add 25 sublist lines t...
# suitescript
a
What's the efficient way to add 25 sublist lines to a record?
Can we do it asynchronously server side?
s
How long is it taking currently? Is there a performance issue? I generally wouldn’t worry about the speed of a script, unless it is a user event script, since they can slow down record saves.
a
@scottvonduhn yes it is a user event script and that's exactly the issue saving the record takes time
How would you do that in UE and can we do it asynchronously?
d
The best method is to use the parent-child relationship method.
a
@dcrsmith could you please explain more or share an example?
s
There is a PDF in SA article id 46388 that describes the parent-child approach starting on page 38: https://netsuite.custhelp.com/app/answers/detail/a_id/46388
They also recommend delegating that to a scheduled script,. You could then submit the scheduled script task from your UE, and it will run independently, so the UE script won’t have to wait for that to finish.
a
What about asynchronous task?
Is that possible?
s
Submitting a separate script task is asynchronous, for all practical purposes.
a
How do you normally add lines? What's the method?
s
Are these transaction lines, or associated child records?
d
Sorry my response was delayed. Thanks for posting that @scottvonduhn That SAFE GUIDE has some good information in it.
s
It would make a big difference in the approach
a
Associated child record
s
i would use a separate scheduled or map/reduce script
the parent-child method is more for doing it synchronously, but avoiding governance limits, so it’s not necessarily the best for performance
a
In that MR script
What function will you use
To add lines
s
you just create the records, and make sure the parent list/record field is set appropriately
no need to do anything with the parent
a
I mean how you do it
Insertline
Setcurrentsublist
I'm using Select newline Then Setcurrentsublistvalue Then Commitline
For every line
Maybe I need to use different methods
b
If you care about speed, the most basic option is to make your changes in beforeSubmit
a
@battk what about these lines
I'm using Select newline Then Setcurrentsublistvalue Then Commitline
Would you do the same?
b
Not an option beforeSubmit
Also probably slower than not dynamic mode
If the beforeSubmit is too slow, then you want to do the work in a scheduled or map/reduce script instead
The link to the SAFE guide is a solid reference for your options
a
@battk what's the difference in dynamic mode?
We don't need to commit the line for each line?
d
^^^ I recently discovered the fact you don't need to commit every line when looping. I think this is only when using selectNewLine. Someone else might have more detail on that.
a
So how would you write the loop without commit?
setting sublist values without dynamic mode consists of using Record.setSublistValue(options)
a
@battk thanks, and with dynamic?
b
documented in the same place as setSublistValue
keep in mind that i wouldnt expect dynamic vs standard mode to make any real difference in performance
using beforeSubmit to make your changes vs after Submit will have a noticeable difference
a
And why is that?
Also do we need to commit for each line or no?
b
using after submit means you are saving the record twice
using before submit means you are saving the record once
if you want to understand the behavior of dynamic mode, play with sublists in the ui
a
So when I do it before submit I don't need to load and save the record?
b
correct, doing so will cause errors
a
Thanks