Question, could a client script add a description ...
# suitescript
n
Question, could a client script add a description line underneath each line if that line has a box checked as that line gets added in the UI?
d
yes
n
Thank you @David B what entry points should I use?
d
if by "as that line gets added" you mean when the user commits the line by pressing "ok", then you should use `validateLine`: SuiteScript 2.x Client Script Entry Points and API
n
Awesome, thank you!
👍 1
@David B Sorry to bother you again, I am new to scripts, and I couldn't get it to work. Seems like I can only replace the line, but not add a line underneath the current line after clicking "Add" or "Ok" button. And I am not sure how to fix it...
Copy code
function validateLine(scriptContext) {
    var currentRecord = scriptContext.currentRecord
    var sublistName = scriptContext.sublistId
    // var field = scriptContext.fieldId
    // var line = scriptContext.line
    // log.debug('Index', line)

    if (sublistName === 'item') {

        if (currentRecord.getCurrentSublistValue(sublistName, 'custcol_is_returnable') === true) {
            currentRecord.selectNewLine(sublistName)
            currentRecord.setCurrentSublistValue(sublistName, 'item', 3984)
            currentRecord.commitLine(sublistName)
        }
    }

    return true;
    
}
d
try committing the existing line, then adding your new line (when I've done this, I haven't then committed the new line, but it should be fine to). Also, it's good to see you're returning true, that's sometimes forgotten. The only other tips I have (not knowing your exact use-case): if you press "ok" on an existing line, should a description item line be added every time? or should the script first check to see whether the following line is already the description item (in your example, with internal id "3984") if a line with the
custcol_is_returnable
checkbox checked was inserted into the item sublist, should the resulting description line be added at the bottom, or inserted as the very next line. If the latter, you should look to use
record.insertLine()
instead of
record.selectNewLine()
. Let us know how you go *edit: formatting/grammar