- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-11-2022 02:52 PM
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:
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!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-23-2022 10:20 PM
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:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-11-2022 04:11 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-14-2022 03:46 PM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-11-2022 06:13 PM
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
Harish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-14-2022 03:46 PM
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.