Rejection reason suitelet Page

We can use rejection reason suitelet page in the workflow to add why the approver rejected the request . Suitelet script is deployed and use the Go to Page action in the workflow to open the custom Page.

/**
 * @NApiVersion 2.1
 * @NScriptType Suitelet
 */
/*************************************************************************************
 ***********
 * XSEED Education Pte Ltd​-IND-NS
 *
 * XSEED-529 : BOM Revision Approval Workflow
 *
 *
 *************************************************************************************
 ***********
 *
 *
 * Author: Jobin and Jismi IT Services LLP
 *
 * Date Created : 21-September-2023
 *
 * Description: The script help to open a suitelet page and user can enter reason for rejection.
 *
 * REVISION HISTORY
 *
 * @version 1.0 XSEED-529 : 21-September-2023 : Created the initial build by JJ0125
 *
 *
 *************************************************************************************
 **********/
define(['N/record', 'N/https', 'N/ui/serverWidget', 'N/redirect'],

    (record, https, serverWidget, redirect) => {

        let main = {
            /****************************************************************************
            * CREATE THE ENTRY POINT OF THE SCRIPT.
            * FORM WRITE PART IS DONE
            * **************************************************************************/
            /**
             * Defines the Suitelet script trigger point.
             * @param {Object} scriptContext
             * @param {ServerRequest} scriptContext.request - Incoming request
             * @param {ServerResponse} scriptContext.response - Suitelet response
             * @since 2015.2
             */
            onRequest: function (scriptContext) {
                var form = main.custFormFunction(scriptContext);
                scriptContext.response.writePage(form);
            },
            /****************************************************************************
            * CREATE THE FORM.
            * SETIING VALUES TO FORM.
            * SETTING VALUE IN TO RECORD.
            * REDIRECT THE FORM.
            * FORM WRITE PART IS DONE
            * **************************************************************************/

            custFormFunction: function (scriptContext) {
                let url = scriptContext.request.headers.referer
                log.debug("url", scriptContext.request.headers.referer)
                let bomRevId = main.getParameterByName('id', url);
                log.debug("bomRevId", bomRevId)
                let form = serverWidget.createForm({ title: 'BOM REVISION REJECTION FORM', hideNavBar: false });
                form.addFieldGroup({ id: 'enterReason', label: 'ENTER THE REASON FOR REJECTION' });

                let rejectReason = form.addField({
                    id: 'custpage_reject_reason',
                    type: serverWidget.FieldType.TEXTAREA,
                    label: 'Enter the reason',
                    container: 'enterReason'
                })
                rejectReason.isMandatory = true;
                rejectReason.updateDisplaySize({ height: 3, width: 50 });

                let bomRevisionVal = form.addField({
                    id: 'custpage_est_id',
                    type: serverWidget.FieldType.TEXT,
                    label: 'TXT',
                    container: 'enterReason'
                })
                
                bomRevisionVal.updateDisplayType({ displayType: serverWidget.FieldDisplayType.HIDDEN });
                bomRevisionVal.defaultValue = bomRevId;

                form.addSubmitButton({ label: 'SUBMIT' });
                if (scriptContext.request.method == 'POST') {
                    let rejReason = scriptContext.request.parameters.custpage_reject_reason;
                    log.debug("rejReason", rejReason);
                    let bomRecIdVal = scriptContext.request.parameters.custpage_est_id;
                    log.debug("bomRecIdVal", bomRecIdVal);
                    let bomRevision = record.load({
                        type: record.Type.BOM_REVISION,
                        id: bomRecIdVal,
                        isDynamic: true
                    });
    
                    // Set the new description
                    bomRevision.setValue({
                        fieldId: 'custrecord_jj_rejection_reason_xseed529', // Replace with the actual field ID
                        value: rejReason
                    });
                    bomRevision.save();
                    redirect.toRecord({
                        type: record.Type.BOM_REVISION,
                        id: bomRecIdVal
                    });
                }

                return form;



            },

            /****************************************************************************
            * FUNCTION FOR GET RECORD ID FROM SCRIPT CONTECT URL.
            * **************************************************************************/

            getParameterByName: function (name, url) {
                if (!url)
                    return false;
                name = name.replace(/[\[\]]/g, "\\$&");
                let regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
                    results = regex
                        .exec(url);
                if (!results)
                    return null;
                if (!results[2])
                    return ' ';
                return decodeURIComponent(results[2].replace(/\+/g, " "));

            }


        }
        /****************************************************************************
        * FUNCTION FOR TRY CATCH.
        * **************************************************************************/

        for (let key in main) {
            if (typeof main[key] === 'function') {
                main[key] = trycatch(main[key], key);
            }
        };

        function trycatch(myfunction, key) {
            return function () {
                try {
                    return myfunction.apply(this, arguments);
                } catch (e) {
                    log.error("ERROR in  " + key, e);
                }
            }
        };
        return main;
    });


Leave a comment

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