How to fill original PO link in Source PO Field when making a copy of that record.

Key Points:- 
Script Type:- User Event
Script Context:- Before Load
Script Context Type:- Copy
Note:-Create a custom transaction field naming as SOURCE PO as shown below
/**
 * @NApiVersion 2.1
 * @NScriptType UserEventScript
 */
define(['N/record'],
    /**
 * @param{record} record
 */
    (record) => {
        /**
         * Defines the function definition that is executed before record is loaded.
         * @param {Object} scriptContext
         * @param {Record} scriptContext.newRecord - New record
         * @param {string} scriptContext.type - Trigger type; use values from the context.UserEventType enum
         * @param {Form} scriptContext.form - Current form
         * @param {ServletRequest} scriptContext.request - HTTP request information sent from the browser for a client action only.
         * @since 2015.2
         */
        const beforeLoad = (scriptContext) => {
            if (scriptContext.type==='copy'){
               // log.debug("rec",scriptContext.request.parameters.id)
                var poId=scriptContext.request.parameters.id
                var currentRec = scriptContext.newRecord;
                currentRec.setValue({
                    fieldId:'custbody_source_po',
                    value : poId});
            }

        }

        /**
         * Defines the function definition that is executed before 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 beforeSubmit = (scriptContext) => {
         
        }


        /**
         * 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) => {

        }

        return {beforeLoad, beforeSubmit, afterSubmit}

    });

Avatar photo

By Nandesh

I’m a Junior Software Engineer in Kerala, a Graduate with a passion for computer science, and electrical engineering.

Leave a comment

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