create a approval record using a script

adam_webster
Kilo Contributor

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

7 REPLIES 7

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


Jeff60
Kilo Expert

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 😉

Jeff60
Kilo Expert

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);

 

find_real_file.png

I hope it can help someone !