- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-18-2013 11:15 AM
I guess this can be used almost anywhere, but as my colleague wanted it for reporting, I shall put it here 🙂
Basically a colleague wants to run a report based on the members of a group, but he does not want to maintain the list - especially on scheduled reports. I did not quite find what I was looking for on here, but I found the seeds and created the following
this is a Global Business Rule and is called group_members
the script :
function group_members(group){
var answer = '';
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('group.name',group);
gr.query();
while(gr.next()){
if(answer != ''){
answer += ',' + gr.user.user_name;
}else{
answer = gr.user.user_name;
}
}
return answer;
}
from a report you choose your field, set the filter to be "is one of" and then in the condition you add "javascript:group_members('group_name');
Only add one javascript per condition as otherwise it does not work
Solved! Go to Solution.
- Labels:
-
Service Mapping
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-21-2013 03:02 AM
I was not having any problems as it all ran well.
I was looking into something else and came across a best practice and it was mentioned that you should not have a business rule set to the "Global" table as it loads everywhere and to make it into an include
Until then and on the examples I had seen, all script includes were called by
var foo = new include();
res = foo.function();
Which will not work for a report.
The page just showed i could make an include a single function so still call the Script Include via group_members()
Done that and it works well.
ServiceNOW is new to us so while I am happy working with the system I am still learning and hunting around many docs /wiki / community comments. I find I can do one thing and then maybe see another way to do it.
We have also taken on some remote support from ServiceNOW and they have done an ACE report on our system and this business rule was also flagged - clearly they did the report before I changed it that day.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-06-2013 11:59 AM
This should be moved to Cool Stuff 🙂
Thank you for posting this, I have something pretty close in my arsenal as this type of thing comes up fairly often. This will make it so others don't have to go through the effort so thank you for sharing!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-19-2013 06:08 AM
After investigating a problem I have, I have now moved this to a Script Include
http://wiki.servicenow.com/index.php?title=Business_Rules_Best_Practices
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-20-2013 07:42 PM
Out of curiosity, what problem were you having?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-21-2013 03:02 AM
I was not having any problems as it all ran well.
I was looking into something else and came across a best practice and it was mentioned that you should not have a business rule set to the "Global" table as it loads everywhere and to make it into an include
Until then and on the examples I had seen, all script includes were called by
var foo = new include();
res = foo.function();
Which will not work for a report.
The page just showed i could make an include a single function so still call the Script Include via group_members()
Done that and it works well.
ServiceNOW is new to us so while I am happy working with the system I am still learning and hunting around many docs /wiki / community comments. I find I can do one thing and then maybe see another way to do it.
We have also taken on some remote support from ServiceNOW and they have done an ACE report on our system and this business rule was also flagged - clearly they did the report before I changed it that day.