I have a script to replace a GL account with anoth...
# suitescript
l
I have a script to replace a GL account with another one in journal entries (I'm doing the if logic for the specific account I want to replace in the mass update UI page). However, when I run it on the UI, there is a SuiteScript error which states that Department and Class are mandatory (which is really the case). Does it mean that when I'm replacing the account, I'm removing the department and class in the original line as well?
b
ss2 index starts at 0
z
Answer is YES. SetCurrentSublistValue plus isDynamjc:true works the same way as you enter data on the UI form. When you change account on UI form I suppose that department and class are going to be reset.. If you want to hold same value, save old values in local variables before setting account
l
Thanks to both of you.
I tried to get and set all fields related to the JE lines that I want to update. The error I get now is "You have attempted an invalid sublist or line item operation. You are either trying to add or remove lines from a static sublist." SyiteAnswers isn't that helpful. Thanks.
b
assuming your journal entry lines are editable
l
Yes, they are editable on the UI.
b
thats the kind of error you can get from messing up the indexes
l
message has been deleted
Uhmmm, that's weird. I started from 0 and it seems that my for loop is in the proper place.
b
nope
how many lines do you have
l
Could be thousands in one single JE
b
pick the one you are having problems with
preferably as few lines as possible
l
I just checked and all of them have thousands of lines.
I created a dummy one, btw. It has literally two lines only.
b
use that one
l
The same errors appears. I forgot to mention that I was testing it on that two-line JE.
b
makes the lesson easier
will the loop run when the i is 0
l
I used 0 and I got the error above. I used 1 and the error now is You have attempted an invalid sublist or line item operation. You are either trying to access a field on a non-existent line or you are trying to add or remove lines from a static sublist. I check SA. Dynamic scripting is enabled in my code above.
Does it matter that I am using setcurrentsublistvalue on a memo field?
b
its more of a thought experiment for your code
i personally can tell that your code is wrong on indexes
and im trying to walk you though why, mostly because its a loop fundamental
so the question is will your for loop run the code inside it when i is 0
for the question, the code inside doesnt matters, its if the value of i will pass your condition in your code that matters
l
The log.debug works. I would say yes.
b
what will itemCount be equal to
p
<=
l
It logs 2 which is right 'cause I have 2.
b
will your for loop run the code inside it when i is 1
similarly, will your for loop run the code inside it when i is 2
p
Not sure you're listening to @battk really. Ask yourself - should it be zero or 1 indexed? If zero indexed, why use
<=
, which would give an extra iteration ?
l
So, it seems like I should start at 1 then?
b
so the question becomes, why did your loop run 3 times when you only have 2 lines
l
So, it seems like I should start at 1 then?
When I get and set the new value, it is not successful. There's that second error.
b
that will make it run twice
however it will run when i is 1 and 2
and your code will select lines 1 and 2
i will tell you that ss2 indexes start at 0
so there is no line 2
l
Oh I get it now. I forgot to update the < from =<. I was so pressured 'cause I needed to get it done at 6pm EST that I didn't even see that. Why do I need to embarrass myself here. Haha. Well, thank you so much!
🤭 1