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
- Create Custom Record
- Navigate to Customization > List, Records, & Fields > Record Types > New
- Name:Enter Workflow Reject Reason
- Click Save
- Click Workflow Reject Reason
- Click Fields
- Click New Field
- Label: Enter Reject Reason
- Type: Select Text Area
- Click Save
- Click Fields
- Click New Field
- Label: Enter Journal Entry
- Type: Select List/Record
- List/Record: Select Transaction
- Record is Parent: Enter Checkmark
- Click Save
- Edit Workflow
- Navigate to Customization > Workflow > Workflows
- Journal Approval Workflow: Click Edit
- Click Reject State
- Bottom right corner: Click New Action
- Click Go to Record
- Basic Information:
- Trigger On: Select Entry
- Parameters:
- Record Type: Select Workflow Reject Reason
- Field:
- Field: Select Journal Entry
- Selection: Select Current Record
- Click Add
- Click Save
- 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
};
});