Creating approval requets in sysapproval_approver not triggering notification rule

FP123
Kilo Expert

I have a workflow which creates a catalog task and then in the advanced section of the create task, I programmatically create an approval request for the catalog task using the below code:

var gr=new GlideRecord('sysapproval_approver');
gr.initialize();
gr.sysapproval=workflow.scratchpad.taskid;
gr.approver=current.variables.XXXXCatalogItem_Approver.toString();
gr.state='requested';
gr.insert();

I am trying to create a Notification Rule to send a customised approval notification email to clients when this type of catalog task/approval request is created. Approval rule is as follows:

find_real_file.png

The problem I have is the above rule is not being triggered when the approval request is created as part of the task. It works fine if I manually create an approval request on the SCTASK after it is created (i.e. just add via the Approvers tab on the catalog task).

I'm thinking the creation by code approach is not triggering an approval.insert event but not sure how to sort that out.

Any assistance would be greatly appreciated!

1 ACCEPTED SOLUTION

FP123
Kilo Expert

Just to circle back on this one. ServiceNow support ended up providing the answer. Issue was I was creating sys_approval record as part of the catalog task advanced script. Issue was that the notification rule was being triggered before the task record was created. Needed to add a wait between creating the catalog task and the sys_approval record. 

Ended up changing my workflow to be:

find_real_file.png

View solution in original post

5 REPLIES 5

FP123
Kilo Expert

Just to circle back on this one. ServiceNow support ended up providing the answer. Issue was I was creating sys_approval record as part of the catalog task advanced script. Issue was that the notification rule was being triggered before the task record was created. Needed to add a wait between creating the catalog task and the sys_approval record. 

Ended up changing my workflow to be:

find_real_file.png