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

Can you please ONLY share instance URL and I will take a look.


Please find below, just to highlight that tomorrow I have a demo with the customer on this instance. Thanks for your help.



https://dev21184.service-now.com/


I just tested for one of the record "INC0010166" and I see assignegrouprole was populated. I also updated business rule to BEFORE and removed current.update().


As I mentioned don't use current.update() in before business rule to avoid performance issues.



Let me know if you have any questions.


Hi Kapil,



Did you try this in a Before Business rule/Onupdate? Also what type of field is x_95063_servicenow_assigneegrouprole?



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, previous);



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