Search code examples
javascriptnetsuitesuitescript2.0

beforeLoad suitescript netsuite


i create an script beforeLoad if status Pending Fulfillment or approval

function beforeLoad(context) {
    

    var currRec = context.newRecord;
        var status = currRec.getValue('status')
        var mem = currRec.getValue('memo')
        var idSo = currRec.getValue('id')
        // log.debug('status', status)
        if (status === 'Pending Fulfillment') {
            record.submitFields({
                type: record.Type.SALES_ORDER,
                id: idSo,
                values: {
                    trandate: null
                },
                
            });
        } else if(status === 'Pending Approval'){
            record.submitFields({
                type: record.Type.SALES_ORDER,
                id: idSo,
                values: {
                    trandate: null
                },
                
            });
        }
    
    }

but when view an sales order that trandate not response. only when once refresh, the script worked


Solution

  • If I understood correctly, you want trandate to be null on record load. What's happening here is once beforeLoad triggers, it runs the code underneath it and then loads the record on the browser. The data you submitted will not reflect on the record until the next refresh since the requested data was the previous (before new value submission).

    You also cannot setValues on beforeLoad entry point. However, it will only apply on new records created (beforeLoad on Edit).

    What is the reason for clearing the trandate after the record is created? If it's to be a business standard requirement, why not run that code after you create the record and clear the trandate on afterSubmit. Though I don't know if you will get thrown an error since it is a mandatory field.