How to insert approvals using a script

sk59
Tera Expert

Hi All,

I would like to insert an approval using a BR. Please let me know how to achieve this.

I have a field ABC(glide_list), I want to add the approvers in this field as approvers when a change is completed.

 

Thanks in Advance

1 ACCEPTED SOLUTION

Hi,


Sorry below one is the corrected script:

 

(function executeRule(current, previous /*null when async*/) {

// Add your code here
var app = current.u_groups;//Where groups are selected
gs.addInfoMessage(app);
var spl = app.split(',');
var len = spl.length;

for(var i=0;i<len;i++)
{
gs.addInfoMessage(i);
var m = new GlideRecord('sysapproval_group');
m.initialize();
m.parent= current.sys_id;
m.assignment_group = spl[i];
m.approval = 'requested';
m.insert();
}
})(current, previous);

 

Thanks,

Ashutosh 

 

Don't forget to mark it as correct

View solution in original post

23 REPLIES 23

Hi Ashutosh,

Record got created but it looked something like this.

find_real_file.png

HI,

 

What i will suggest is to try below code with hardcoded value of approver.

 

Use below code:

var m = new GlideRecord('sysapproval_approver');
m.initialize();
m.sysapproval= current.sys_id;
m.approver = 'Give sys id of user in this single quotes';
m.state = 'requested';
m.insert();

Let me know if the approver name come's in or not.

Thanks,
Ashutosh Munot

Approver name has come now.

Hi, Since you have mentioned a glide list field here. so just modify the above script and this would work.


var usr= current.field_name.split(',');
for (var i = 0; i < usr.length; i++)

{

var m = new GlideRecord('sysapproval_approver');
m.initialize();
m.sysapproval= current.sys_id;
m.approver = usr[i];
m.state = 'requested';
m.insert();

}

if this can be done through workflow approval then, use:

var answer;

var usr= current.field_name.split(',');
for (var i = 0; i < usr.length; i++){

answer.push(usr[i]);

}

 

else simply in the workflow approval , set the field to use as ABC.

Hi Ashutosh,

I need to do this by script instead of workflow.

The same script is used earlier where the approver and assignement group values are coming as blank