create a approval record using a script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-05-2017 02:02 AM
Hi,
I need assistance creating an approval record using a script. Can you someone please assist me with the script
var approval_gr = new GlideRecord('sysapproval_approver');
approval_gr.initialize();
approval_gr.state = 'Cancelled';
approval_gr.approver = '';
approval_gr.source_table = '';
approval_gr.document_id = '';
approval_gr.insert();
Thanks,
Adam
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-05-2017 07:48 AM
Have you tried this
var approval_gr = new GlideRecord('sysapproval_approver');
approval_gr.initialize();
approval_gr.state = 'requested';
approval_gr.approver = gs.getUserID(); //Replace with approver from current record
approval_gr.sysapproval = current.sys_id; //Current is record that requires approval
approval_gr.insert();
Thanks
Please Hit like, Helpful or Correct depending on the impact of the response

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-10-2020 07:12 AM
Hi,
I would like use your script to add users from fields as Approval :
- 1 x field type "reference" with one value
- 1 x field type "reference" with one or more value.
After order, my "Run script" in the Workflow retrieve value from this two fields and add users like approval.
// Retrieving fields values.
tm = current.variables.team_manager;
pa = current.variables.project_administrator;
// Add users in fields as Approval
var approval_gr = new GlideRecord('sysapproval_approver');
approval_gr.initialize();
approval_gr.state = 'requested';
approval_gr.approver = gs.getUserID(); // ???
approval_gr.sysapproval = current.sys_id; // ???
approval_gr.insert();
Thanks for your help 😉

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-10-2020 09:19 AM
Hi,
I found this :
In a Workflow, i use an Core Activities "Approval - User" with this Advanced Approvers Script :
// Retrieving fields values.
tm = current.variables.team_manager.sys_id; //Retrieve value from current field type "Reference"
pa = current.variables.project_administrator.toString(); //Retrieve value from current field type "List Collector"
// Add users in fields as Approval
answer = [];
answer.push(pa);
answer.push(tm);
I hope it can help someone !