How do you write script to add Approvers under a catalog task?

SooraC
Tera Contributor

Hi team, 

 

On submit, I want to modify the script to add 'Approvers' when automatically creating a Catalog Task. I currently have this code:

  var app = new GlideRecord('sysapproval_approver');
  app.initialize();
  app.approver = '[sys_id]';
  app.insert();
 
 
but it doesn't add any approvers. 

Screenshot 2024-11-21 153237.png
Would any of you know how to modify the script to add "Approvers"?
1 ACCEPTED SOLUTION

Brad Bowman
Kilo Patron
Kilo Patron

You can create approvals via script, but in this case you also want to link the approval to the sc_task record so that it shows on the Related List.  Your current script may be creating orphaned approval records, or there could be a Business Rule or Data Policy in place to prevent the insert if not all of the required fields are populated. Here the fields that I have populated when creating approval records via script.  I've only ever created approvals at the RITM level - when approval is required before the flow/workflow continues to scripts/Catalog task, etc. but the script should work the same at the Catalog Task level...

var app = new GlideRecord('sysapproval_approver');
app.newRecord(); //newer method than initialize(), but either still works
app.approver = '[sys_id of user]';
app.sysapproval = '[sys_id of sc_task record]';
app.source_table = 'sc_task';
app.document_id = '[sys_id of sc_task record]';
app.state = 'requested';
app.insert();

 

View solution in original post

10 REPLIES 10

You are welcome!