Or `findSublistLineWithValue`?
# suitescript
e
Or
findSublistLineWithValue
?
a
If you can directly use
findSublistLineWithValue
with the
uniquekey
and that is going to return the line number you need to use
setSublistValue
or
setCurrentSublistValue
.
e
uniquekey
works in N/query but not in
findSublistLineWithValue
The field doesn't seem to exist / be exposed / have the same name 🤔
a
It 100% does work with
findSublistLineWithValue
but it will not work on beforeSubmit because you don't have a
lineuniquekey
yet. Maybe you have a field ID problem: Query wise it may be
uniquekey
, record wise it is:
lineuniquekey
.
e
Toying around in the console. Both return
undefined
, other fields work fine.
a
For the expense sublist it may be different.
☝️ 1
e
Maybe it's the
line
column? Not sure what gets stored there
e
It's funny. Line
0
retrieves line
1
🤡
a
That is accurate; lines start at 1, and the sublist lines, tho, SuiteScript 2.x-wise, start at 0.
line
does not equal the sublist line position. If you add or remove lines, the
line
value will increase regardless of how many lines you end up in the sublist. You could have a sublist with only two lines and line 0(sublist position) could be with line value of 1 while line 1 (sublist position) could have a line value of 20, because ~20 insert or remove operations happened in between.
e
Seems like for the
expense
sublist, you're going to have to manufacture your own hash to match line items 😞
e
Ouch
Thanks everyone, we tried 😕
c
@Edgar Valdes With a heap of caveats that I've only kicked this around a bit, and there could always be edge cases I haven't encountered, the following worked for me. To test, I created an expense report with a few lines, then edited it, inserted a line, saved it, then edited it again, deleted a line, inserted one, and added a new line before saving. In other words, I tried to create a transaction where the order of line addition / sequence was jumbled to some degree. In this snippet, I get the line ID from N/query using the transaction ID and line unique key (really, only the latter is needed, but I like suspenders with my belts), then use the line ID in
findSublistLineWithValue()
to get the line number. I then use the line number in
getSublistValue()
to prove to myself that it gets the value I expect. Of course, you could use this for the sublist line edit you need. Hopefully this helps! I'll close by reiterating my caveat you should thoroughly test before trusting 😄
e
Thanks, Clay, will give it a try thankyou
c
Sure thing @Edgar Valdes, let me know how it goes! I did notice the possibility of a relationship between
transactionline.linesequencenumber - 1
and the sublist line number, but for some reason, I distrust that
e
So far it works 🙏
🎉 1
c
That's great, I'm glad to hear it!