RE: Client Script Question – Create one column field(“Serial No:”) on transaction record ,set this field value to line sequence number.

Here I already created Serial No field, but it should populate automatically as sequence number whenever the user enters the new line items or for already existed line items. Still after running the script nothing is showing in the execution log. Why ?

function sublistChangedSetSrNo(scriptContext) {
            try {
                //alert(scriptContext)
                var currentRecord = scriptContext.currentRecord;
                //get the line count of item sublist
                var  lineCount = currentRecord.getLineCount({
                    sublistId: 'item'
                });
                log.debug('lineCount',lineCount)
                // we should do loop through line and set the value of the serial.no field to the line sequence no.
                for (var i = 0; i < lineCount; i++){
                log.debug('line',i)
                currentRecord.selectLine({sublistId: 'item',line: i});
                    // set the value of the serial.no field to the line sequence no.
                    currentRecord.setCurrentSublistValue({
                        sublistId: 'item',
                        fieldId: 'custcolcol_serial_no',
                        value: i + 1
                    });
                    currentRecord.commitLine({
                        sublistId: 'item'
                    });
                }
            } catch (e) {
                log.error({
                            title: "error entry",
                            details: e
                        });
            }
        }
    return {
        validateLine: validateLine,
        sublistChanged: sublistChangedSetSrNo
    };
Devyani_Jain Rookie Asked on June 14, 2023 in SuiteScript.
Add Comment
1 Answers

Hi,

I think you need to consider when this should run and does the user need to see it in real time?

 

Real Time

If editing an existing record which does not already have entries, then you should probably use pageInit to set default values.

For new lines, you would typically use lineInit to set the values.

 

Not Real Time

A User Event script could make sure that there is an entry for each row in beforeSubmit. This would work for new and existing records.

 

Thanks,

Chris

Advanced Answered on June 16, 2023.
Add Comment

Your Answer

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