Hey all, I've been having a bit of a problem with ...
# suitescript
m
Hey all, I've been having a bit of a problem with Suitescript 2, involving line items. In Suitescript 1, there are two basic ways to set line item data. (1)
nlapiSetLineItemValue()
and (2)
nlapiSetCurrentLineItemValue()
. However, in Suitescript 2, it seems that only the equivalent to
nlapiSetCurrentLineItemValue()
is available on the
context.currentRecord
passed to a client script (as
currentRecord.setCurrentLineItemValue()
). Has anybody found a substitute for the original
nlapiSetLineItemValue()
(where I don't have to
currentRecord.selectLine()
and then
currentRecord.commitLine()
)? This is important for my use case because sometimes the
fieldChanged
event triggers after a line is added in my experience.
a
its been a WHILE since I did any SS1, but I wanna say its always been this way? can you use nlapiSetLineItemValue() in a client context? is that not just available server side?
... doesn't look like you should be able to
the equivalent is in the record module rather than the currentRecord module, but in the record module its only for standard mode, not dynamic mode, and in a client context you're effectively always in dynamic mode... so I think its just the same as it ever was, it just looks a little different
m
@Anthony OConnor Yeah, it's always worked for me... ironically enough, I use it all of the time on the 'description' field and custom fields. Basically... it lets me perform actions on lines that don't happen to be the 'selected' one at the time. Never really had a problem with it not working.
Ah darn... that stinks. Well... guess I'll need to reason about all of this a little differently than.
I think there might even be a few scripts I can't transfer over... a few have line items that aren't dependent on other line items for things like date fields.
a
if you're having issues with field change trigger, maybe move to validate line or post sourcing or something?
m
I could do that... but it wouldn't cover all use cases 😕
Let me give an example... Let's say I have a script that on a regular field triggers a change to a date field on a non-selected line (suppose the user is currently typing something in).
a
uh huh
m
In SS2, I'd need to go and select that line (dropping whatever the user is typing), make the change, then select the other line they were changing
Hmmm
Well... I'll try and figure something our
out*
Thanks for your help on this 🙂
a
don't make the change while they're typing! what?!
do it when they commit that line
m
I could do that, but then I'd need to make the script remember that the change was occuring and that it needed to trigger on validateLine
or more precisely... after validate line
let's say the change happens on a fieldChange() event
I'd have to remember the fieldChange until another event
anyways... just seems a little more of a hassle than I want it to be... but I'll figure something out XD
Thanks again.
a
i think validate line should be fine for this? you get the current line date field, you select the other line (presumably the next one but maybe its reference somewhere on the current line?) you do whatever calc you're doing to the original date to get your target date, and then compare target date with the date currently in the target date field.. if they match do not match make the update ... and return true;
m
@Anthony OConnor I think that might work... although I haven't tested it out much. Either that or sublistChanged (though there is some funky stuff with that if it correlates with recalc() from SS1)
a
good luck 🙂
👍 1