Requirement
Include the Payment Event Reason (from the Billing tab) in the Cancel Sales Order email template. Since this field is inline and not directly mappable to the email template, a workaround is required.
Solution Overview
To surface the Payment Event Reason in the email template:
- Create a custom transaction field on the Sales Order (e.g.,
custbody4) to store the reason. - Develop a User Event Script to extract the reason from the inline field or subrecord.
- Map the custom field to the Cancel Sales Order email template.
🔁 Script Logic Summary
@NApiVersion 2.x @NScriptType UserEventScript @NModuleScope SameAccount
🔍 Execution Flow:
- Trigger: Runs on
CREATEorEDITof Sales Order. - Step 1: Attempts to fetch
paymenteventholdreasondirectly. - Step 2: If not found, accesses the
paymenteventsubrecord and retrievesholdreason. - Step 3: Compares with existing value in
custbody4. Skips update if already set. - Step 4: Loads the Sales Order, sets
custbody4with the reason, and saves the record.
🧠 Key Fields:
paymenteventholdreason paymentevent.holdreason custbody4
✅ Benefits
- Ensures the cancel reason is consistently captured and visible in client-facing communication.
- Avoids manual entry or template limitations by automating the mapping.