RE: How to Set a Sublist Value in a Client Script

Hi, I have child record sublist that I want to be able to manage from the parent record (both parent/child are custom records). There’s a checkbox field called “Current” on the child indicating the current child record. I want to be able to toggle this checkbox where it’s mutually exclusive among the other child records, similar to address subrecords where there can only be one default billing address and when you check one address it unchecks the other.

The way I’m trying to accomplish this is with a client script that uses validateLine. When  the “Current” checkbox is set to true on a line, I iterate through all the other lines and set Current = false. The problem is the currentRecord module will allow me to set the current sublist field with setCurrentSublistValue, but it won’t let me set other sublist fields, which ordinarily would be done with setSublistValue. The currentRecord module apparently doesn’t have the latter method, and I need it for my iteration, because I need to change the other sublist lines to false when the current line is set to true by the user.

Is there a way to do this without having the setSublistField method for the currentRecord module?

mmascitto Beginner Asked on September 17, 2019 in SuiteScript.
Add Comment
1 Answers

Client script’s programming model doesn’t do multi line logic well. You would need to use CurrentRecord.selectLine followed by CurrentRecord.commitLine to select a line and then later commit it. Keep in mind that your client script (and sadly other client scripts) probably need to be written so that the changes to the other lines do not trigger unwanted logic.

You might also want to consider using sublistChanged instead of validateLine

Advanced Answered on September 17, 2019.

Ok. Does sublistChanged let me know which line was changed? Because I’ll need to know which line the user just set to true so I can mark the others false.

on September 17, 2019.

CurrentRecord.getCurrentSublistIndex. Keep in mind that you will be changing the value returned by CurrentRecord.getCurrentSublistIndex when you select different lines.

on September 17, 2019.

How do i prevent an infinite loop? My entry point is sublistChanged. The problem is when I use selectLine and commitLine to change the values of the other lines, it triggers sublistChanged again.

on September 20, 2019.

Thats my warning about writing logic to ignore the changes to the other lines. You can try using a checkbox field to denote that the sublist changes should be ignored in your script. You can do something similar with just a variable. The variable approach tends to not be as useful to other scripts unless the variable is global.

on September 24, 2019.

So I’ve tried using selectLine, setCurrentSublistValue (using the ignoreFieldChange), then commitLine, but I’m still getting caught in an infinite loop. It looks like when selectLine is executed, it re-triggers the sublistChanged entry point and never makes it through the rest of the loop. The i variable is always zero. It never increments.

Below is my code. Basically it looks for when the user sets the “Current” field to true on a line, then loops through all other lines and sets the Current field to false. Any suggestion on how to stop the infinite loop? NetSuite does this natively for default address on the address sublist, so you’d think there’s a way to do it.

RE: How to Set a Sublist Value in a Client Script

on September 24, 2019.

Follow my suggestion of ignoring changes made by your for loop bY returning early in the recursive sublistChanged events. Setting ignoreFieldChange will not help in this regard.

on September 26, 2019.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.