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

lakng
Tera Contributor

my team did not felt good approach going with array, so have created a table and had created one reference field which will point to the list of groups.

so can u suggest me with code, how can i approach this way

okay. I can understand that if there are lot of groups best to store in a table. So i have modified the code to read the data from the table. In below code, change the tablename and column to your data and check.

//Query your table and get teh groups into this array. This way, you don't need to hardcode anything.
var groups = [];
var gr_groups = new GlideRecord("your_table");
gr_groups.query();
while(gr_groups.next()) {
groups.push(gr_groups.getValue("your_column"));
}



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 if it helps.

lakng
Tera Contributor

hi Asif,

do i need to change the parent sys_id here in the code?

what about array we are using in this code? do we need this still as we have created a table and stored

and when it has to work, before update / insert update?

Yes, the array is needed for comparison. 

if you are going to create a BR on sysapproval_group table, then create it after insert and put the code like this. Add a condition for approval is requested so that it runs only for the approvals which are requested.

If you want to run only for change requests then add another condition AND

say parent startswith CHG

 

//Query your table and get teh groups into this array. This way, you don't need to hardcode anything.
var groups = [];
var gr_groups = new GlideRecord("your_table");
gr_groups.query();
while(gr_groups.next()) {
  groups.push(gr_groups.getValue("your_column"));
}

var arrayUtil = new ArrayUtil();
//check if the assignment group falls in our groups.
gs.log("Entered into the BR");
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="not_required";
}

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

lakng
Tera Contributor

have tried and no logs has entered in system logs after executing this. seems some problem with this Asif.