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

asifnoor
Kilo Patron

Hi,

I don't think you can write a BR here, unless you want this script to run on some insert/update of a specific table.

Here is the script which you can use to update the approval.

//add groups to the array like this. You need to use Group sys_ids

var groups = ["b85d44954a3623120004689b2d5dd60a","287ee6fea9fe198100ada7950d0b1b73","287ebd7da9fe198100f92cc8d1d2154e"];

var gr = new GlideRecord("sysapproval_group");
//put your Change request sys_id below.
gr.addQuery("parent","41cdb152db252200a6a2b31be0b8f527");
gr.addQuery("approval","requested");
gr.query();
var arrayUtil = new ArrayUtil();
while(gr.next()) {
   //check if the assignment group falls in our groups.
  if(arrayUtil.contains(groups, gr.getValue("assignment_group"))) {
    //If yes, then update approval to no longer required.
    gr.approval="not_required";
    gr.update();
  }
}

Mark the comment as  a correct answer and helpful once worked.

 

lakng
Tera Contributor

hi Asif, thanks for the help.

first we have bulk of assignment groups, all these groups should be in one array.

so, if the approvals added for these related groups then approvals has to set "No Longer required"

 

Hi,

The first line in my script does that. All your group sys_ids to that array named groups.

Go through my comments and it shall guide you.

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

lakng
Tera Contributor

hi asif, i have created new table and having one field in it which will be pointing out to all the given groups.

now i need business rule logic to check if the approval group is belongs to this table groups, then the approvals has to set NO longer required.

Hi,

Please check the code that i gave to you.

The first line takes the groups into an array.

Then it queries the sysapproval_group and look for approvals which are in requested state for a particular CR.

And then it will check if any of the approval group presents in our array, if yes, then it will update the approval status to No longer required.

Not sure, if you want anything else.

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