Assignment Rule, Current Record & query

poyntzj
Kilo Sage

In a script include, is there a way to run an encoded query against the current record and return if it has a match ?

Intend to make Assignment Rules a lot easier for the end users and a lot more flexible.  It works fine on a record that has been saved and then edited, but if course a new record does not work.

The code will get all of the lookup records that match the target table and quickly determines which rule will match the target record in its' table.  If there is a match  it will set the assignment group based on the next steps.(It knows the sys_id of the current record so is looking for that with the matching condition sys_id=123123^category=software.....)

Of course, as that is querying the target table (incident, change_request etc) it needs the record to exist to work

When creating a new record, when the assignment code runs I can see that current exists, but until the record is saved the query will fail as it is not in the table.  I want to avoid an insert with an immediate update (which does work)

I was hoping that by doing a current.addEncodedQuery('bla bla') that may work, but it does not.

Anyone have any other ideas - I don't really fancy trying to break down a query string and going down that route

 

TIA

 

 

1 ACCEPTED SOLUTION

Brian Dailey1
Kilo Sage

Hi poyntzj,

I would suggest you try using GlideFilter. Here's a reference, take a look.

GlideFilter - CheckRecord

It does essentially what you ask, comparing a GlideRecord to a string filter (encoded query). Give that a try and see if it works for your scenario.

 

Thanks,
-Brian

 

Edit:

Here's an example used in an on Before business rule for Incident:

(function executeRule(current, previous /*null when async*/) {
	// If the Impact is HIGH, set the Urgency to HIGH as well.
	var bool = GlideFilter.checkRecord(current, "impact=1");
	if(bool){
		current.setValue('urgency', 1);
	}
})(current, previous);

View solution in original post

6 REPLIES 6

SanjivMeher
Kilo Patron
Kilo Patron

I think you should use an after insert/update BR for this. and call the script include from the BR, That will make sure the record is submitted and then run the lookup.


Please mark this response as correct or helpful if it assisted you with your question.

Problem with this Sanjiv is that the code under "system Policy | rules | assignment" and then as a "script" runs before the save so it can populate the Assignment group / assigned to on save.

The workaround I had before was a quick BR on task that if the ticket was inserted would run as an onAfter, force an update and save.  this would trigger the assignment a second time and as the record now existed in the table it would run and assign.

In a background script creating a variable called current and calling a record works with an addEncodedQuery as it knows it is from a table whereas in the assignment code it does not.  the GlideFilter works on "current" so a quick change of code and it is working nicely

using "current" also lowers the overheads as there is no querying from the table (looking for a sys_id and the filter) for each of the rules that apply.