Sorry, my mistake.
# suitescript
a
Sorry, my mistake.
s
this must be pseudocode, or you've written wrappers for the native API?
a
yes, pseudocode.
s
that's actually a cool idea to help workaround the lame
every function takes an object
design choice NS made.
one thing I'd recommend is not doing this in dynamic mode unless you have to. In my experience dynamic mode is less predictable
a
what shall I do in dynamic mode?
s
that looks reasonable enough, but being pseudocode/wrappers the problem may be hidden therein.
a
I have to do it in client script
no there is no hidden problem
100%
s
I personally recommend avoiding hand written loops to avoid looping errors
a
so what would you do
s
I mean the code you posted above is not valid SuiteScript so the real code may have some issue.
what I would do is use NFT and write it something like (example, a sales order working with item sublist)
Copy code
const so = new SalesOrder(ctx.record)
_.map(so.item, line => line.somefield = somevalue)
(note no loops mentioned)
I like your shortened object literal notation though, for cases where I have need to store the values in variables before invoking the native APIs. As long as you name the variables the same as the function parameter object properties you're good to go with that abbreviated syntax. Looks clean.
a
In my experience dynamic mode is less predictable
@stalbert could you please explain more
and how can I avoid dynamic mode
s
dynamic mode tries to mimic a user entering data on-screen
if you're doing something that relies on certain field sourcing or other dynamic behavior that would happen as a user fills out a line on the form then you may need dynamic mode
otherwise just use standard mode
the code snippet I included above automatically uses dynamic mode if
ctx.record
is in dynamic mode, otherwise it defaults to standard mode apis.