- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2017 07:28 AM
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
Solved! Go to Solution.
- Labels:
-
Incident Management

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2017 07:47 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2017 08:00 AM
Hi Pradeep,
below code works fine when used in a script include however not sure why it is not working when used in after business rule.
var HelloWorldSN = Class.create();
HelloWorldSN.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
helloWorld: function() {
var gr1 = new GlideRecord('sys_group_has_role');
gr1.addQuery('group', this.getParameter('sysparm_groupName'));
gr1.query();
if(gr1.next())
return gr1.getDisplayValue('role');
//return "Hello " + this.getParameter('sysparm_user_name') + "!";
},
type: 'HelloWorldSN'
});

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2017 08:02 AM
Thanks for the update Kapil. The Same code will not work in BR as both have different syntax. You will have to adjust your code.
Did you try with the code I have shared above?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2017 08:20 AM
Thank you Pradeep,
your code is working however current.setValue('x_95063_servicenow_assigneegrouprole',"itsm"); is not setting value without current.update();

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2017 08:22 AM
Is this on your personal dev instance?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2017 08:26 AM
Yes Pradeep...