Scripting Catalog Task Approval

sstgermain
Tera Contributor

I am attempting to have a Group Approval created at the task level when I issue a Catalog Task from workflow. I have embedded the following script in the Catalog Task workflow item.

var ar = new GlideRecord('sysapproval_group');
var grp = new GlideRecord('sysapproval_group');
grp.addQuery('name', '=', 'Group Name');
target.query();
ar.initialize();
ar.approver = grp.sys_id;
ar.state = 'requested';
ar.sysapproval = current.sys_id;
ar.source_table = 'sc_task';
ar.document_id = current.sys_id;
ar.description = 'Test Approval Description';
ar.insert();

While the task is created fine, the group approval on that task is not. Can anyone provide a suggested solution?

Thanks

3 REPLIES 3

Mark Stanger
Giga Sage

Group approvals are just a task record. They don't extend or use the approval table. To create a group approval, you should set the 'assignment_group' field with the sys_id of the approving group and the 'parent' field with the sys_id of the task you want to approve. Creating a group approval record in this way will them create the individual approval records for users in that group.


Mark,

Thanks for the reply. It may be over complicated, especially given your response, but wanted to post how this was resolved, to share with the community and for 'future generations' to improve upon.

In a workflow, on a Catalog Task, I enabled scripting and inserted the following to create and 'anchor' to the created Catalog Task:

task.correlation_id = current.number + 'unique workflow stream text';

*The 'unique text' is to ensure there is a truly unique anchor to a specific path in the workflow, allowing the use of anchors in other streams of the same workflow and not grab those task numbers instead. See attached images for visual.

I disable 'Wait for completion' so the workflow doesn't wait at the Catalog Task until it is closed or cancelled. Then, insert a Run Script step immediately after the Catalog Task that 'matches itself' to the appropriate anchor from the Catalog Task, then creates the Group Approval. See attached TXT file for the full script.

Cheers,



Thanks for the solution Steven