The CreatorCon Call for Content is officially open! Get started here.

how can i fetch groups in to an array

lakng
Tera Contributor

i want to fetch few groups in an array,

after that if the change request is having approval for this groups the Approval automatically has to set No longer Required.

so here how can i write an business rule, which will check the approval group, if the approval group is one of these fetched ones, then the approval has to set "No longer Required"

 

1 ACCEPTED SOLUTION

Hi,

so can you add a log above if and print current.assignment_group and groups array and check what the value it contains.

Technically,both should be group sys_ids and if you think the assignment group present in your list of groups, then manually verify the sys_id of assignment group in the groups array or in your table.

Mark the comment as a correct answer and helpful if it helps.

View solution in original post

48 REPLIES 48

i mean check the value inside that table for that CR sys_id.

Call me. May be it is faster to fix it.

lakng
Tera Contributor

i have check this script in back ground script, yeah it is working fine cancelling the approvals 

can you please change this script for using the same in BR, as i tried and facing some issues.

 

var grGroupApproval = new GlideRecord('sysapproval_group');

grGroupApproval.get('df75eba41b924054a01f2f876e4bcb6a');

 

 

 

var grChange = new GlideRecord('change_request');

grChange.get(grGroupApproval.parent);

gs.log('parent '+ grGroupApproval.parent + ' risk ' + grChange.risk);

if(grChange.risk==4)

{

gs.print('calling 1');

var groups = [];

var gr_groups = new GlideRecord("u_epic_group_approvals");

gr_groups.query();

while(gr_groups.next()) {

groups.push(gr_groups.getValue("u_epic_group_approvals"));

 

  var arrayUtil = new ArrayUtil();

  gs.log("Entered into the BR " +grGroupApproval.assignment_group.getDisplayValue());

  if(arrayUtil.contains(groups, grGroupApproval.assignment_group)) {

    gs.log("Entered into the If condtion"+grGroupApproval.approval+"-------"+grGroupApproval.sys_id);

    gs.eventQueue("TEstBR",grGroupApproval,grGroupApproval.sys_id,grGroupApproval.approval);

  }      

            gs.print('calling 2');

}

}

Here you go. But this will work only if the risk is updated before the approval is changed to requested.

If the value of risk in CR is updated after the approval entry changes to requested, then your Br executes first and it will not have the value of risk by that time.

var grGroupApproval = new GlideRecord('sysapproval_group');
grGroupApproval.get(current.sys_id);

var grChange = new GlideRecord('change_request');
grChange.get(grGroupApproval.parent);

gs.log('parent '+ grGroupApproval.parent + ' risk ' + grChange.risk);
if(grChange.risk==4)
{
  gs.print('calling 1');
  var groups = [];
  var gr_groups = new GlideRecord("u_epic_group_approvals");
  gr_groups.query();
  while(gr_groups.next()) {
    groups.push(gr_groups.getValue("u_epic_group_approvals"));
  } 
  var arrayUtil = new ArrayUtil();
  gs.log("Entered into the BR " +grGroupApproval.assignment_group.getDisplayValue());
  if(arrayUtil.contains(groups, grGroupApproval.getValue("assignment_group"))) {
    gs.log("Entered into the If condtion"+grGroupApproval.approval+"-------"+grGroupApproval.sys_id);
gs.eventQueue("TEstBR",grGroupApproval,grGroupApproval.sys_id,grGroupApproval.approval);
  }      
            gs.print('calling 2');
}

lakng
Tera Contributor

hi Asif,

i have one more requirement, when the assignment group of the change request is related to EPic groups (we have list of epic related groups stored in one table), then if change management group approvals are added to sysapproval_group, automatically the approvals has to set as "No longer Required"

you can modify this BR accordingly.

var groups = [];
var gr_groups = new GlideRecord("u_epic_group_approvals");
gr_groups.query();
while(gr_groups.next()) {
groups.push(gr_groups.getValue("u_epic_group_approvals"));
}


var grChange = new GlideRecord('change_request');
grChange.get(current.parent.toString());
gs.info(' change number '+ grChange.number + ' risk ' + grChange.risk);
var riskval = grChange.risk.toString();

if(riskval=='4')
{


var arrayUtil = new ArrayUtil();
//check if the assignment group falls in our groups.
gs.log("Entered into the BR " +current.assignment_group.getDisplayValue());
if(arrayUtil.contains(groups, current.assignment_group)) {
//If yes, then update approval to no longer required.
gs.log("Entered into the If condtion"+current.approval+"-------"+current.sys_id);
gs.eventQueue("EpicApprovalsAutoCancel",current,current.sys_id,current.approval);

}
}

find_real_file.pngfind_real_file.png

Hi,

Could you create a new post and let me know.