The CreatorCon Call for Content is officially open! Get started here.

Trigger Approval Notification on state changes

Deepika Gangra1
Tera Expert

Hi All,

I have a requirement to trigger approval notification only when state changes to Pre-Check Completed (custom state) on RITM. Currently It triggering only when approver is attached to RITM not on the states changes.
Please find the below event , BR , Notification condition overview and let me know where need to adjust the code.

event Name :precheck.completed
Table :sc_req_item

Br: Trigger Notifctaion on RITM PreCheck / After - Update
Table :Sc_req_item 
script :

(function executeRule(current, previous /*null when async*/) {
    if (current.state.changesTo(15)) {
   
        gs.eventQueue("precheck.completed", current, current.requested_for, gs.getUserID());
    }
})(current, previous);

Notification
Table: sysapproval_approver
Condition: 
sysapproval.getTableName() == 'sc_req_item' && sysapproval.state == 15

Looking forward for your response.

Thank you in Advance!

8 REPLIES 8

When using an event as the trigger, you want your Table to be the one that contains the data to be included in the email message, so sysapproval_approver is correct in your scenario,  Remove the Condition from the notification as that is redundant - the event should only fire/trigger when the State is correct.  The Business Rule changes are also not what you want as the event will now fire every time the RITM is updated and in the State, rather than only when the RITM State changes to your desired state.  Put the Business Rule back the way you had it, then update a RITM record to this state.  Check the System Logs > Events or System Policy > Events > Event Log to see if the Business Rule correctly fired the event.

Ankur Bawiskar
Tera Patron
Tera Patron

@Deepika Gangra1 

why not send the approval only when State Changes to Pre-check completed ? This is much easier to handle.

This way you need not create any BR, make any changes to OOTB notification etc?

You can make your Service Catalog Flow on your catalog item to wait till RITM State moves to Pre-check completed

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hi @Ankur Bawiskar , 
Thanks for reply,

No fulfiller wants to see the approver also , once he moved the state to Pre check completed only then approvers get notified.

@Deepika Gangra1 

that's what I am saying.

Trigger approval only when State Changes to your state and it will work for you.

You can use Wait logic in your flow associated to your catalog item.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader