Dynamic Filter: Incident Updated by != member of Assignment Group

JP-ODU
Tera Guru

I've been trying to find a way to get a dynamic filter working for use in condition builder on incident list view, in the Flow Designer, etc. The relevant filter people are looking for is "update by field | is not | a member of the assignment group"

We have a script includes named IncidentHelperFunctions that runs this for a List style (it puts a blue dot on ticket numbers for Incidents where updated by != member of assignment group: 

var IncidentHelperFunctions = Class.create();
IncidentHelperFunctions.prototype = {
	initialize: function() {
	},
	
	getUpdatedByMembership: function(current){
		if(!gs.getUser().getUserByID(current.sys_updated_by.toString()).isMemberOf(current.assignment_group)){
			return true;
		}else{
			return false;
		}
	},
	
	type: 'IncidentHelperFunctions'
};

So, I thought it was just a matter of creating a Dynamic Filter calling this script? I made the following

find_real_file.png

I thought the referenced table should be sys_user, as I thought that's what populates the updated by field?

But, in practice, the dynamic filter isn't coming up when trying to filter by Updated by, there are no dynamic options for updated by:

find_real_file.png

The Member is Assignment Group dynamic filter is, for some reason, pulling under Assigned To:

find_real_file.png

But, when applied here, it turns "empty:"

find_real_file.png

Can anyone spot how I'm doing this wrong? Is it how I'm configuring the filter, or do I fundamentally misunderstand the script? How can I get a dynamic filter that checks if X field (updated by, especially) contains a user who is a member of the incidents assignment group?

1 ACCEPTED SOLUTION

Michael Jones -
Giga Sage

Dynamic query filters can only be applied to Reference fields, and the update by field is a string field (which contains the user_name of the last person to update the record). So, I don't believe you will be able to use that condition for that field (and that is why you do see it for Assigned To, which is a reference field). 

That being said, however, when you are filtering a list view with a condition you don't have access to values for current. If you look at the other examples for dynamic they are related somehow to the user (me, one of my groups, etc.) or something external to the current record itself that can be applied to a query. 

You could, for example, make a script include that would get all of the members for groups that the user is a member, build a list of user_names and then exclude any records updated by those users from your list, but I don't believe you would be able to build a filter that would show only records updated by someone who is not in the assignment group this way. 

The only way that I can think of to make a query like this one demand would be to create a script include that would query the table, check for all active incidents, check the members of the assignment group, and if the sys_update_by is not a member of that group push the sys_id to an array. Then call that script with a query against sys_id - is one of - with a value of javascript:callYourScript();

You could then copy the URL and make a module with a link that URL to make it more easily repeatable. 

I hope this helps!

If this was helpful, or correct, please be kind and mark the answer appropriately.

Michael Jones - Proud member of the GlideFast Consulting Team!

I hope this helps!
Michael D. Jones
Proud member of the GlideFast Consulting Team!

View solution in original post

3 REPLIES 3

Ravi9
ServiceNow Employee
ServiceNow Employee

Seems like sn doesnt want you to create dynamic filters on non reference fields ?

refer this doc link , it doesnt seem to refer anything other than reference if am not mistaken !

here is a snippet

Dynamic filter options enhance filtering by allowing users to run existing script includes or JavaScript against a reference field within condition builders and dynamic reference qualifiers.

Michael Jones -
Giga Sage

Dynamic query filters can only be applied to Reference fields, and the update by field is a string field (which contains the user_name of the last person to update the record). So, I don't believe you will be able to use that condition for that field (and that is why you do see it for Assigned To, which is a reference field). 

That being said, however, when you are filtering a list view with a condition you don't have access to values for current. If you look at the other examples for dynamic they are related somehow to the user (me, one of my groups, etc.) or something external to the current record itself that can be applied to a query. 

You could, for example, make a script include that would get all of the members for groups that the user is a member, build a list of user_names and then exclude any records updated by those users from your list, but I don't believe you would be able to build a filter that would show only records updated by someone who is not in the assignment group this way. 

The only way that I can think of to make a query like this one demand would be to create a script include that would query the table, check for all active incidents, check the members of the assignment group, and if the sys_update_by is not a member of that group push the sys_id to an array. Then call that script with a query against sys_id - is one of - with a value of javascript:callYourScript();

You could then copy the URL and make a module with a link that URL to make it more easily repeatable. 

I hope this helps!

If this was helpful, or correct, please be kind and mark the answer appropriately.

Michael Jones - Proud member of the GlideFast Consulting Team!

I hope this helps!
Michael D. Jones
Proud member of the GlideFast Consulting Team!

praneeth7
Tera Guru

Hi @JP-ODU 

 

Can you achieve it?