Work Order Complete

This sample code triggers a notification to be sent to the recipient specified in the Notification Preferences page when a work order status is updated to complete.

You can copy and paste this sample code in Application Composer > Objects > Standard Objects > Work Order > Server Scripts.

/* DISCLAIMER: This trigger is provided only as a reference.
*  TRIGGER TYPE: Before Update to Database
*  OBJECT: Work Order
*  Use Case: Send a notification when a work order is completed.
*  Note: You can override the Notification Text and Recipients using the Notification Preferences page.
* When WO_STATUS_CD is exposed in Application Composer, this script can be changed. Change everywhere that says 'WoStatusCdMeaning' to 'WoStatusCd'
* and change the comparison in the if statement to 'ORA_SVC_WO_COMPLETE' instead of 'Complete'.
*/

if (isAttributeChanged('WoStatusCdMeaning') && WoStatusCdMeaning == 'Complete') {
    try {
        def messageText = WoId.toString() + ':' + WoNumber + ' - This Work Order has been Completed'
        def recipientPartyId = AssigneeResourceId
        def recipientName = AssigneePersonName
        if (recipientPartyId) {
            adf.util.sendNotification(adf, messageText, recipientPartyId)
            //Log a confirmation that the notification has been sent. Logs can be viewed in 'Runtime Messages'.
           //println("Notification sent to " + recipientName + " because status of WO is Complete")
        } else {
            println("No Assignee associated with this Work Order")
        }
    } catch (e) {
        //Log the failure in groovy logging. Logs can be viewed in 'Runtime Messages'.
        println("Failure to trigger notification from Groovy Script " + e.getMessage());

// Throwing validation exception will show the message on the UI. This is not recommended for published sandboxes.
// The following code is one of many to illustrate identifying an error in trigger from the UI.
// Replace <triggerName> with the trigger name you specified when creating this trigger
// throw new oracle.jbo.ValidationException('Failure to trigger <triggerName> Notification from Groovy Script: ' + e.getMessage())
   }
}