Custom Child Record Sublists using Script

Whether we can update the custom child record sublist using script in a record?Yes, It’s possible by scripting.

The custom record child record will be inline editor sublist that contains a list of records. There was a concern that whether we can add line into the sublist that are custom record list in the item fulfillment record. For that create a child record and make it in item fulfillment subtab. And consider it as normal sublist and add lines into it . You can do:-

  • you can add/edit/remove lines dynamically prior to submitting the form
  • you can add/edit/remove lines using the UI or SuiteScript
  • when writing client scripts, use record.cmmitLine(options) or currentRecord.commitLine(options) after each sublist line change. Otherwise your changes will not be saved to NetSuite.
  • when writing server scripts, you must call record.commitLine or currentRecord.commitLine(options)  to save sublist updates. Note that you must do this in addition to calling record.save(),  which saves the entire record object to the database.
  • Sample code for updating the same in a item fullfilmment record is
/**
 * @NApiVersion 2.1
 * @NScriptType UserEventScript
 */
define(['N/record'],
    /**
     * @param{record} record
     */
    
    (record) => {
        /**
         * Defines the function definition that is executed after record is submitted.
         * @param {Object} scriptContext
         * @param {Record} scriptContext.newRecord - New record
         * @param {Record} scriptContext.oldRecord - Old record
         * @param {string} scriptContext.type - Trigger type; use values from the context.UserEventType enum
         * @since 2015.2
         */
        const afterSubmit = (scriptContext) => {
                try{
                        log.debug("entered try catch")
                        if(scriptContext.type === scriptContext.UserEventType.EDIT){
                                log.debug("entered context")
                                var newRecord = scriptContext.newRecord
                                var recordId = scriptContext.newRecord.id
                                var itemFulfillment = record.load({
                                        type: record.Type.ITEM_FULFILLMENT,
                                        id: recordId,
                                        isDynamic: true
                                })
                                var lineCount = itemFulfillment.getLineCount({
                                        sublistId: "recmachcustrecord_ofippl_transaction",
                                })
                                log.debug("linecountfirst", lineCount)

                                itemFulfillment.selectNewLine({
                                        sublistId: 'recmachcustrecord_ofippl_transaction'
                                })
                                log.debug("selected new line")

                                itemFulfillment.setCurrentSublistValue({
                                        sublistId: 'recmachcustrecord_ofippl_transaction',
                                        fieldId: 'custrecord_ofippl_printstatus',
                                        value: 2
                                })
                                log.debug("value set")

                                itemFulfillment.setCurrentSublistValue({
                                        sublistId: 'recmachcustrecord_ofippl_transaction',
                                        fieldId: 'custrecord_ofippl_error',
                                        value: "Test by suitscript"
                                })
                                log.debug("value set")

                                itemFulfillment.commitLine({
                                        sublistId: 'recmachcustrecord_ofippl_transaction'
                                })
                                log.debug("commitedline")

                                //linecount
                                var lineCount = itemFulfillment.getLineCount({
                                        sublistId: "package",
                                })
                                log.debug("linecount", lineCount)
                                        //loop through number of lines in PO
                                        itemFulfillment.save();
                        }
                }catch(error){
                        log.debug("error@aftersubmit")

                }

        }
        return {afterSubmit}
    });

When working with custom child record sublists you can use all the modules provided in SuiteScript.

Leave a comment

Your email address will not be published. Required fields are marked *