Clear the fields when we add same item using the make a copy/copy previous button in the purchase order record

/**
 * @NApiVersion 2.1
 * @NScriptType ClientScript
 * @NModuleScope SameAccount
 */
  /**
     * @param{record} record
     * @param{format} format
     */
    function (record, format) {


        /**
         * Validation function to be executed when sublist line is committed.
         *
         * @param {Object} scriptContext
         * @param {Record} scriptContext.currentRecord - Current form record
         * @param {string} scriptContext.sublistId - Sublist name
         *
         * @returns {boolean} Return true if sublist line is valid
         *
         * @since 2015.2
         */
        function validateLine(context) {


            try {
                var currentRecord = context.currentRecord;
                log.debug("currentRecord", currentRecord);
                var sublistName = context.sublistId;
                log.debug("sublistName", sublistName);
                // Check if the sublist is 'item' 
                if (sublistName === 'item') {
                    var timestampValue = currentRecord.getCurrentSublistValue({
                        sublistId: 'item',
                        fieldId: 'custcol_jj_time_stamp'
                    });
                    log.debug("timestampValue", timestampValue);
                    // If timestamp value is not available, set a new timestamp
                    if (!timestampValue) {
                        var newTimeStamp = format.format({
                            value: new Date(),
                            type: format.Type.DATETIME
                        });


                        currentRecord.setCurrentSublistValue({
                            sublistId: 'item',
                            fieldId: 'custcol_jj_time_stamp',
                            value: newTimeStamp
                        });
                    }
                    else {
                        log.debug("inside else", "inside else");
                        currentRecord.setCurrentSublistValue({
                            sublistId: 'item',
                            fieldId: 'custcol_mhi_ibs_buyer_commission_rec',
                            value: ''
                        });
                        currentRecord.setCurrentSublistValue({
                            sublistId: 'item',
                            fieldId: 'custcol_mhi_ibs_not_eligible_reason',
                            value: ''
                        });
                        currentRecord.setCurrentSublistValue({
                            sublistId: 'item',
                            fieldId: 'custcol_mhi_ibs_not_eligible_comm',
                            value: false
                        });


                    }
                }
                return true; // No repeated items found
            } catch (e) {
                log.debug("error @ validateLine", e)
            }
         }
       return {


            validateLine: validateLine,


        };


    });

Leave a comment

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