Capturing Payment Event Reason in Cancel Sales Order Email

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:

  1. Create a custom transaction field on the Sales Order (e.g., custbody4) to store the reason.
  2. Develop a User Event Script to extract the reason from the inline field or subrecord.
  3. 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 CREATE or EDIT of Sales Order.
  • Step 1: Attempts to fetch paymenteventholdreason directly.
  • Step 2: If not found, accesses the paymentevent subrecord and retrieves holdreason.
  • Step 3: Compares with existing value in custbody4. Skips update if already set.
  • Step 4: Loads the Sales Order, sets custbody4 with 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.

Leave a comment

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