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

Muhammad Khan
Mega Sage
Mega Sage

Hi FP123,

 

I am not sure how your workflow is structured, but I would suggest you to go with Approval Activities as per your requirement.

 

Hopefully, it will work for you.

Thanks Muhammad, appreciate the reply. I am using the code because this approval is for a catalog task level approval, not a requested item one.

Harish KM
Kilo Patron
Kilo Patron

Hi you dont need the above script . Just use approval user activity and pass the below script

var answer = [];

answer.push(current.variables.XXXXCatalogItem_Approver.toString()); // this  line will insert approver 

Regards
Harish

Thanks Harish, appreciate the reply. I am using the code because this approval is for a catalog task level approval, not a requested item one.