Filter User with Title in Script Include
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2024 12:28 AM - edited 03-20-2024 12:29 AM
Hi There,
I have a requirement to filter users having 'Regional Director' or 'Regionsdirektør' title in user table and assign them approver role.
We already have scheduled script which runs daily to scan the users who need approver role and the functions we have defined in script include. I have to add one more function to the script which is to assign approver role to the users having 'Regional Director' or 'Regionsdirektør' title.
I tried adding the below function to the script include but its not working
(Note: All functions are working correctly except the below function. I have added the new function to the end of the script include)
New Function:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2024 12:56 AM
@Community Alums
Seems like there are a few issues with your _isRegionalDirector function.Please try with updated code:
_isRegionalDirector: function(userRecord) {
var grTitle = new GlideRecord("sys_user");
grTitle.addQuery('title', 'Regional Director');
grTitle.addOrCondition('title', 'Regionsdirektør');
grTitle.addQuery('sys_id', userRecord.sys_id); // Limit search to the current user
grTitle.query();
return grTitle.hasNext(); // Return true if there's at least one matching record
},
Please Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2024 03:12 AM
Hi @Maddysunil,
Thank you for your reply, I changed the condition little bit but it's not adding users having "Regionsdirektør" title to the group
Script:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2024 03:33 AM
@Community Alums
Your current approach uses titleSTARTSWITHRegionsdirektør in an encoded query to match titles that start with "Regionsdirektør". However, this might not be the most effective way to check for a specific title, especially if the title might contain additional characters or words.
_isRegionalDirector: function(userRecord) {
var grTitle = new GlideRecord("sys_user");
grTitle.addQuery('title', 'Regionsdirektør'); // Query for exact title match
grTitle.addQuery('sys_id', userRecord.sys_id); // Limit search to the current user
grTitle.query();
return grTitle.hasNext(); // Return true if there's at least one matching record
},
Please Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2024 03:44 AM
Hi @Maddysunil ,
I tried the exact script but it's still not assigning role to the user.
Thanks,
Tejas