Add more criteria to encoded query
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2024 11:10 AM
Hello,
I need to exclude HR groups to this query please assist.
Thanks,
Chad
Add exclusion of HR Groups Type is Human Resources and Parent is not HRSD.
typeNOT LIKE7a5370019f22120047a2d126c42e705c^parent!=904c25b01b00525c62cb2139b04bcb34
To
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2024 09:52 PM
Hi @purdue
Could you clarify whether you’re aiming to extend the exclusion for the Reference qualifier of the Group variable, to prevent users from selecting HR groups?
Or are you looking to exclude HR groups from the query within the groupsExclusion function?
Cheers,
Tai Vu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2024 08:39 AM
Probably best to add to function but nothing I am doing works so I thought I would add to the reference qualifier to see if that works. Any assistance is appreciated.
Thanks,
Chad

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2024 09:53 AM - edited 10-17-2024 09:54 AM
Is the result from gs.getProperty("groups.to.exclude") a comma-delimited list of sys_ids? If not, the first part of the query won't work. If it is returning that, maybe flip it and put the other part first?
query = 'typeNOT LIKE7a5370019f22120047a2d126c42e705c^parent!=904c25b01b00525c62cb2139b04bcb34^sys_idIN' + gs.getProperty("groups.to.exclude");
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2024 10:02 AM
I'm not seeing the response I crafted yesterday afternoon. I'll try to remember, restate, and improve upon it. What you really need to do is simplify the reference qualifier and Script Include by combining these into one function. This will be easier to troubleshoot and have the benefit of one trip to the server/script include. Here's what your reference qualifier should look like:
javascriptt:'active=true^sys_idNOT IN' + new AssignmentGroupMaintenancecAjax().groupExclusion();
(without the extra t in javascript that I added so that this editor won't mess it up)
The Script Include will look more like this, to work with this reference qualifier, declare the 'qry' variable, which I just noticed you weren't doing, and I changed the name to make sure it's not a system/reserved word (same with 'group' GlideRecord), and change some other things to the more recommended/supported/safe way:
var AssignmentGroupMaintenanceAjax = Class.create();
AssignmentGroupMaintenanceAjax.prototype = Object.extendsObject(AbstractAjaxProcessor, {
groupExclusion: function() {
gs.addInfoMessage('SI running')
var groupSysIDs = [];
var qry = 'nameIN' + gs.getProperty("servicenow.parent.groups") + '^sys_idIN' + gs.getProperty("groups.to.exclude") + '^typeNOT LIKE7a5370019f22120047a2d126c42e705c^parent!=904c25b01b00525c62cb2139b04bcb34';
var groupGr = new GlideRecord('sys_user_group');
groupGr.addEncodedQuery(qry);
groupGr.query();
while (groupGr.next()) {
gs.addInfoMessage('SI group excluded: ' + groupGr.name)
groupSysIDs.push(groupGr.sys_id.toString());
}
return groupSysIDs.join(',');
},
type: 'AssignmentGroupMaintenanceAjax'
});
This could resolve your issue. If not, I've added some temporary logging so that you can confirm the script is running and see each group name that should be excluded. If you can't see these info messages when you're testing, change them to gs.info then look in the System logs, filtering on Message starts with SI.
If you are still seeing records in the reference list that should be excluded, and you don't see that group name in the logs, then you need to tweak your encoded query. Try manually filtering a list view of the group table to show all of the records that you want to exclude. This should involve adding all of the criteria and selecting or pasting in the values from both system properties. Once you have this list nailed down you can copy the query to the Script Include function and replace the system property concatenations.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2024 02:11 PM
Hello Brad,
Unfortunately this is not working. I even tried to change the parent to see if it what filtering but no luck. Any other ideas? The logs do not generate anything.
Thanks,
Chad