How to trigger notification

rajesh mishra
Tera Contributor

Hello everyone. 

I have a requirement. 

I have configured one notification template on "sysapproval_approver" table. When an RITM generates, this mail triggers to the approver. 

Now the requirement is if the approver does not approve for 48 hours, then again, this notification should trigger to the approver. This should continue till the approver does not approves. 

Could we execute this, if yes then please suggest the procedure.

1 ACCEPTED SOLUTION

AB3
Tera Expert

Yes, you can achieve this by creating a scheduled job that checks for unapproved requests that are older than 48 hours and then triggers the notification. Here are the steps:

 

1. Create a new Scheduled Job: - Navigate to System Definition > Scheduled Jobs. - Click on New to create a new scheduled job. - Give it a name, for example, "Notify Unapproved Requests". - Set the Run field to the desired frequency, for example, every hour.

 

2. In the Script field, add the following JavaScript code: javascript var gr = new GlideRecord('sysapproval_approver'); gr.addQuery('state', 'requested'); gr.addQuery('sys_created_on', '<=', gs.hoursAgo(48)); gr.query(); while (gr.next()) { gs.eventQueue('your.event.name', gr, gr.approver.getDisplayValue(), gr.document_id.getDisplayValue()); } This script queries the 'sysapproval_approver' table for records that are in the 'requested' state and were created more than 48 hours ago. For each such record, it triggers a custom event.

 

3. Create a new Event Registry: - Navigate to System Policy > Events > Registry. - Click on New to create a new event. - Give it a name, for example, "your.event.name". - Set the Table field to 'sysapproval_approver'.

 

4. Modify your Notification: - Navigate to System Policy > Notifications. - Open your existing notification. - Set the When to send field to "When event is fired". - Set the Event name field to the name of your custom event, for example, "your.event.name".

 

5. Save all changes. This setup will cause your notification to be sent whenever the scheduled job finds an unapproved request that is older than 48 hours. The notification will continue to be sent at the frequency you set for the scheduled job until the request is approved.

View solution in original post

2 REPLIES 2

Aman Kumar S
Kilo Patron

You can create a flow, which runs every hour on "sysapproval_approver" table, and for the approvals you can calculate if it has been 48 hours, you can trigger the notification for those records.

 

Best Regards
Aman Kumar

AB3
Tera Expert

Yes, you can achieve this by creating a scheduled job that checks for unapproved requests that are older than 48 hours and then triggers the notification. Here are the steps:

 

1. Create a new Scheduled Job: - Navigate to System Definition > Scheduled Jobs. - Click on New to create a new scheduled job. - Give it a name, for example, "Notify Unapproved Requests". - Set the Run field to the desired frequency, for example, every hour.

 

2. In the Script field, add the following JavaScript code: javascript var gr = new GlideRecord('sysapproval_approver'); gr.addQuery('state', 'requested'); gr.addQuery('sys_created_on', '<=', gs.hoursAgo(48)); gr.query(); while (gr.next()) { gs.eventQueue('your.event.name', gr, gr.approver.getDisplayValue(), gr.document_id.getDisplayValue()); } This script queries the 'sysapproval_approver' table for records that are in the 'requested' state and were created more than 48 hours ago. For each such record, it triggers a custom event.

 

3. Create a new Event Registry: - Navigate to System Policy > Events > Registry. - Click on New to create a new event. - Give it a name, for example, "your.event.name". - Set the Table field to 'sysapproval_approver'.

 

4. Modify your Notification: - Navigate to System Policy > Notifications. - Open your existing notification. - Set the When to send field to "When event is fired". - Set the Event name field to the name of your custom event, for example, "your.event.name".

 

5. Save all changes. This setup will cause your notification to be sent whenever the scheduled job finds an unapproved request that is older than 48 hours. The notification will continue to be sent at the frequency you set for the scheduled job until the request is approved.