Glide Record is not working in Business Rule

kapilscs
Kilo Contributor

Hi All,

Below is my business rule which is trying to fetch Assignee Group role however it is not working, grRole.getDisplayValue('role') is not fetching any value.

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

  //var temVar = new HelloWorldSN();

  //var assinGrp = temVar.func2();

  var assigneeGroup = current.getDisplayValue('assignment_group');

  gs.log("assigneeGroup" + assigneeGroup);

  var grRole = new GlideRecord('sys_group_has_role');

  grRole.addQuery('group',assigneeGroup);

  grRole.query();

  var temRoel = grRole.getDisplayValue('role');

  gs.log("temRoel "+ temRoel);

                              if(grRole.next()){

current.setValue('x_95063_servicenow_assigneegrouprole',"itsm");

  current.update();

  }

})(current, previous);

Regards

Kapil Shinde

1 ACCEPTED SOLUTION

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hello Kapil,



Create a BEFORE business rule with the below modified script. Don't use current.update(); in before business rule to avoid performance issues.


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




  var assigneeGroup = current.getDisplayValue('assignment_group');


  gs.log("assigneeGroup" + assigneeGroup);


  var grRole = new GlideRecord('sys_group_has_role');


  grRole.addQuery('group.name',assigneeGroup);


  grRole.query();


  if(grRole.next())


  {


  var temRoel = grRole.getDisplayValue('role');


  gs.log("temRoel "+ temRoel);




  current.setValue('x_95063_servicenow_assigneegrouprole',"itsm");


  }


})(current, previous);



Reference:


http://wiki.servicenow.com/index.php?title=GlideRecord


View solution in original post

13 REPLIES 13

SanjivMeher
Kilo Patron
Kilo Patron

Hi Kapil,



Try below



var assigneeGroup = current.assignment_group;


  gs.log("assigneeGroup" + assigneeGroup);


  var grRole = new GlideRecord('sys_group_has_role');


  grRole.addQuery('group',assigneeGroup);


  grRole.query();


  var temRoel = grRole.getDisplayValue('role');


  gs.log("temRoel "+ temRoel);


                              if(grRole.next()){



current.setValue('x_95063_servicenow_assigneegrouprole',"itsm");


  current.update();


  }


})(current, previous);



Please mark this response as correct or helpful if it assisted you with your question.

Sai Anna
ServiceNow Employee
ServiceNow Employee

var assigneeGroup = current.getDisplayValue('assignment_group');


  gs.log("assigneeGroup" + assigneeGroup);


  var grRole = new GlideRecord('sys_group_has_role');


  grRole.addQuery('group',assigneeGroup);


  grRole.query();


    if(grRole.next()){     // you need to add next() function


  var temRoel = grRole.getDisplayValue('role');


  gs.log("temRoel "+ temRoel);


                              if(grRole.next()){



current.setValue('x_95063_servicenow_assigneegrouprole',"itsm");


  current.update();


}


  }


})(current, previous);


BALAJI40
Mega Sage

Try this one,



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




  //var temVar = new HelloWorldSN();


  //var assinGrp = temVar.func2();



  gs.log("assigneeGroup" + assigneeGroup);


  var grRole = new GlideRecord('sys_group_has_role');


  grRole.addQuery('group',current.assignment_group); // if assignment group is reference


  grRole.query();


if(gr.next()){


  var temRoel = grRole.getValue('role');;


  gs.log("temRoel "+ temRoel);


                              if(grRole.next()){



current.setValue('x_95063_servicenow_assigneegrouprole',"itsm");


  current.update(); // if it is before business rule do not required current.update


  }


})(current, previous);


Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hello Kapil,



Create a BEFORE business rule with the below modified script. Don't use current.update(); in before business rule to avoid performance issues.


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




  var assigneeGroup = current.getDisplayValue('assignment_group');


  gs.log("assigneeGroup" + assigneeGroup);


  var grRole = new GlideRecord('sys_group_has_role');


  grRole.addQuery('group.name',assigneeGroup);


  grRole.query();


  if(grRole.next())


  {


  var temRoel = grRole.getDisplayValue('role');


  gs.log("temRoel "+ temRoel);




  current.setValue('x_95063_servicenow_assigneegrouprole',"itsm");


  }


})(current, previous);



Reference:


http://wiki.servicenow.com/index.php?title=GlideRecord