Add more criteria to encoded query

purdue
Kilo Sage

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

groupsExclusion: function() {
var groupSysIDs = [];
query = 'sys_idIN' + gs.getProperty("groups.to.exclude");
var group = new GlideRecord('sys_user_group');
group.addEncodedQuery(query);
group.query();
while (group.next()) {
groupSysIDs.push(group.sys_id + "");
}
return groupSysIDs;
},
17 REPLIES 17

You're not even seeing the SI Running log - even if you change it to gs.info...? Make sure you don't have any other Script Includes with this same name, and that your script include name and function are exactly what you are using in the reference qualifier like my examples.  I'm not following the part about changing the parent - did you change the system property value?  Is the Script Include in the same scope as the Catalog Item and reference variable?  

Hello Brad,

I am seeing below it is making it into function but not loop.   

Screenshot 2024-10-18 at 9.41.55 AM.png

That likely means that no records are returned that match 'qry'.  We can confirm that with more logs, along with the system property values so you can make sure those values are pulled into the query, and the values will help troubleshoot how to tweak the qry to what you want based on the manual procedure I described earlier.

var AssignmentGroupMaintenanceAjax = Class.create();
AssignmentGroupMaintenanceAjax.prototype = Object.extendsObject(AbstractAjaxProcessor, {

	groupExclusion: function() {
		gs.info('SI running')
		var groupSysIDs = [];
        var parentProp = gs.getProperty("servicenow.parent.groups");
        gs.info('SI parentProp= ' + parentProp);
        var exProp = gs.getProperty("groups.to.exclude");
        gs.info('SI exProp= ' + exProp);
        var qry = 'nameIN' + parentProp + '^sys_idIN' + exProp + '^typeNOT LIKE7a5370019f22120047a2d126c42e705c^parent!=904c25b01b00525c62cb2139b04bcb34';
		var groupGr = new GlideRecord('sys_user_group');
		groupGr.addEncodedQuery(qry);
		groupGr.query();
        if (!groupGR.hasNext()) {
            gs.info('SI no records found');
        }
		while (groupGr.next()) {
			gs.info('SI group excluded: ' + groupGr.name)
			groupSysIDs.push(groupGr.sys_id.toString());
		}
		return groupSysIDs.join(',');
	},

    type: 'AssignmentGroupMaintenanceAjax'
});

Share the logs if you're still stuck.

 

Hello Brad,

I changed the query to exclude all parent group of all hr groups but still not filtering.  The only log appearing is the SI Running.  

groupExclusion: function() {
gs.info('SI running');
var groupSysIDs = [];
var qry = 'parent!=d1d47b531bf38218e4a76246b04bcbec^parent!=904c25b01b00525c62cb2139b04bcb34^parent!=ff0370019f22120047a2d126c42e702b^parent!=397919781b44de1c62cb2139b04bcb73^parent!=31bc29fc1b00525c62cb2139b04bcb13' + '^nameIN' + gs.getProperty("servicenow.parent.groups") + '^sys_idIN' + gs.getProperty("groups.to.exclude");
var groupGr = new GlideRecord('sys_user_group');
groupGr.addEncodedQuery(qry);
groupGr.query();
while (groupGr.next()) {
gs.info('SI group excluded: ' + groupGr.name);
groupSysIDs.push(groupGr.sys_id.toString());
}
return groupSysIDs.join(',');
},

Everything I said in my last reply still applies and will get to the bottom of the issue.