Hi guys, I have a strange issue that drives me cra...
# suitescript
d
Hi guys, I have a strange issue that drives me crasy. 🙂 In a client script:
Copy code
for (var ln = 0; ln < totalItemsCount; ln++) {
    printLog("Selecting line " + ln);
    currentRecord.selectLine({ line: ln, sublistId: 'item' });
    printLog("Line selected: " + currentRecord.getCurrentSublistIndex({ sublistId: 'item' }));
For some reason it's always line 0 selected. But when I chagne "ln" to for example 2, line 2 is successfully selected. Have anyone faced the same?
n
Not sure, but since you are looping through the sublist and you know your loop index why would you even bother doing that? I suspect that using selectLine does not update whatever is referenced when you use getCurrentSublistIndex. Since selectLine relies on a line number value, it would seem pointless?
d
I use getCurrentSublistIndex to make sure the line was changed indeed. But when I use the variable, it is not changed, when I use hardcoded value, selectLine is working.
So that what I'm seeing in logs when I use the variable: Selecting line 0 Line selected: 0 Selecting line 1 Line selected: 0 Selecting line 2 Line selected: 0
And when I put hardcoded constant (2): Selecting line 0 Line selected: 2 Selecting line 1 Line selected: 2 Selecting line 2 Line selected: 2
b
which entry point are you using
d
In pageInit
b
might want to try using setTimeout to run your code later
the record might not actually be ready
n
I would ignore what it's reporting for line Selected and maybe output a known column to see if the values returned match line 0,1,2 etc? if you've used .selectLine it should work as described.
d
Thanks guys! I decided to move all the logic to beforeSubmit trigger.