What is the equivalent of clicking Add in Client S...
# suitescript
m
What is the equivalent of clicking Add in Client Script (Page Init)? I've tried comitLine which puts the line but doesn't actually add the line. I have a Kit and would like to set some default values on some of the items in the Kit.
s
I don't understand what you mean by
Page Init
, thats when the page is being loaded and does not seem to have anything to do with your scenario. However,
validateLine
should trigger when the line is added.
sublistChanged
probably would as well but I doubt you would get the line number passed in that case.
If you are looking how to functionally click the Add button, then yes
commitLine
would be the like for like action.
m
Thanks. I'm setting the defaults in the page init function. I'm able to insert a line item, but it still requires me to hit the add button. So in order to set item values we should use validateLine...
s
How are you adding the lines?
selectNewLine
,
setCurrentSublistValue
, and
commitLine
should do it. If they aren't then you may need to make sure you
forceSyncSourcing
or you are not filling out some part of the line that is required.
👍 1
m
Copy code
if (item) {
    currentRecord.selectNewLine({
        sublistId: 'item'
    });

    currentRecord.setCurrentSublistValue({
        sublistId: 'item',
        fieldId: 'item',
        value: item
    });
    currentRecord.commitLine({
        sublistId: "item"
    });
}
That inserts the line but doesn't 'add' the line
ah right, this did the trick: forceSyncSourcing
is it possible to set line values at the time it's adding the lines or can I do it after all the lines have been added? I just want to set a checkbox on all the lines to be true
s
You can add more setCurrentSublistValues in there after the first one