- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2019 01:45 AM
Hi there,
I have a non-standard request catalogue item and I want to set the contact type to "self-service" when a request is raised.
I've managed to do this with a on insert business rule, the slight difference is I only want to set this if the opened by is not a member of the say the "service desk" group.
I tried this with adding conditions and listing all the members but I soon realised that if someone leaves I've have to remember to change the business rule.
Is there a way to script this so that I can say only set this condition if the opened by is not a member of like I say the "service desk" group.
Many thanks,
Alex
Solved! Go to Solution.
- Labels:
-
Request Management
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2019 02:42 AM
Hi Alex,
so if opened_by user is not member of service desk then set contact type as self service
use before insert business rule and have this script
script:
var userObj = gs.getUser().getUserByID(current.opened_by);
var isMember = userObj.isMemberOf('Service Desk');
if(!isMember){
current.contact_type = 'self service';
}
Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2019 02:09 AM
Hi Alex
This is untested, but I think you can achieve this by putting something like this in the advanced condition field:
!gs.getUser().isMemberOf('service desk')
Hope it helps.
Matt

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2019 02:21 AM
Hi Alex,
You can query the sys_user_grmember table with the sys_id of the opened by. This will give you information if this user is currently a member of the Service Desk group. Below I have written a function that could be used in this case. Just pass the sys_id of opened by and the name of the group and it will check if this user is a member..
/*
* Check if user is a member of a given group
*
* @param {string} user - sys_id of a user to be checked
* @param {string} groupName - name of the group to be checked
*
* @return {boolean} true if user is a member, false if not
*/
function checkIfUserInGroup(user,groupName) {
var grGroupMember = new GlideRecord('sys_user_grmember'); // GlideRecord for sys_user_grmember table
grGroupMember.addQuery('user.sys_id',user); // user condtition
grGroupMember.addQuery('group.name',groupName); // group condition
grGroupMember.query();
// if there is a record return true
if(grGroupMember.hasNext()){
return true;
}
return false;
}
Hope this helped.
Best regards,
Łukasz
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2019 02:35 AM
Hi Lukasz,
So with this script would I just change anywhere it says groupName with the actual group name?
The way I see this working is that if a member of the Service Desk group logs a request it WON'T set the contact type to self service but if anyone else outside of this group logs a request it WILL set the contact type.
Is that correct?
Thanks,
Alex
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2019 02:42 AM
Hi Alex,
so if opened_by user is not member of service desk then set contact type as self service
use before insert business rule and have this script
script:
var userObj = gs.getUser().getUserByID(current.opened_by);
var isMember = userObj.isMemberOf('Service Desk');
if(!isMember){
current.contact_type = 'self service';
}
Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader