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

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);

To be clear, using GlideFilter applies your encoded query statement against the record you provide to it (in this case, Current), and returns a Boolean true if the condition matches the record. There is no need to initialize/query another GlideRecord. -Brian

Works a treat. Never knew about this little nugget before

I can't take all the credit... Chuck Tomasi clued me in on how to use GlideFilters at the hackathon a few years back. Thanks @ctomasi, -Brian