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,


Where you have to use this script and where is your approvers stored?


Thanks,
Ashutosh Munot

Hi Ashutosh,

I have the glide_list field on Change table which stores the groups and I need to add them as approvers when change state is completed.

HI,


So you can write a after update BR with conditions as State changes to Completed.

 

var app = current.glide_list_field_name;

var spl = app.split(',');

var len = spl.length;

 

for(var i=0;i<len;i++)

{

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

}

 

Thanks,

Ashutosh Munot

HI,


This is working for me :


See Below BR: 

 

And below is approval list:

find_real_file.png

Thanks,
Ashutosh Munot

Hi Ashutosh,

For your case it is working because watch list has the users. find_real_file.png

but in my case the field has the groups

find_real_file.png