Create Reject Reason Page in Workflow

User has a Custom Journal Entry Approval Workflow. User wants Approvers to have a page where they can enter the reason for rejecting the transaction.

Solution
  1. Create Custom Record
    1. Navigate to Customization > List, Records, & Fields > Record Types > New
    2. Name:Enter Workflow Reject Reason
    3. Click Save
    4. Click Workflow Reject Reason
    5. Click Fields
    6. Click New Field
    7. Label: Enter Reject Reason
    8. Type: Select Text Area
    9. Click Save 
    10. Click Fields
    11. Click New Field
    12. Label: Enter Journal Entry
    13. Type: Select List/Record
    14. List/Record: Select Transaction
    15. Record is Parent: Enter Checkmark
    16. Click Save
  2. Edit Workflow
    1. Navigate to Customization > Workflow > Workflows
    2. Journal Approval Workflow: Click Edit
    3. Click Reject State 
    4. Bottom right corner: Click New Action
    5. Click Go to Record
    6. Basic Information:
      • Trigger On: Select Entry 
    7. Parameters:
      • Record Type: Select Workflow Reject Reason
      • Field:
        • Field: Select Journal Entry
        • Selection: Select Current Record
        • Click Add
    8. Click Save
  3. Create SuiteScript
/**
* @NApiVersion 2.x
* @NScriptType UserEventScript
* @NModuleScope SameAccount
*/
define(['N/record'],

function(record) {‌

     function afterSubmit(scriptContext)
     {‌
      // Get the value of the Reject reason
          var rejReason = scriptContext.newRecord.getValue({‌
              fieldId: 'custrecord1'	// Change this according to the internal id of the Field Reject Reason in the Custom Record Created
          });

      // Get the ID of the Journal Entry Created reason
          var journalID = scriptContext.newRecord.getValue({‌
              fieldId: 'custrecord2'	// Change this according to the internal id of the Field Journal Entry in the Custom Record Created
          });

      // populate the Reject Reason in the Journal Entry field
          var id = record.submitFields({‌
              type: record.Type.JOURNAL_ENTRY,
              id: journalID,
              values: {‌
                  custbody1: rejReason	// Change custbody1 to the internal id of the custom field Reject Reason in the Journal Entry Record
              },
              options: {‌
                  enableSourcing: false,
                  ignoreMandatoryFields : true
              }
          });
      }

      return {‌
          afterSubmit: afterSubmit
      };
});

Leave a comment

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