Encoded Query String and GlideRecords

raprohaska
Kilo Guru

This may be an odd question. I have a table where I can define "rules" using a condition field to drive if the rule is applied. This works great when I can query for the records I want to apply the rule to:

var grRules = new GlideRecord('rules');

grRules.addQuery('type', 'incident');

grRules.query();

if (grRules.next()) {

        var grIncident = new GlideRecord('incident');

        grIncident.addEncodedQuery(grRules.condition);

        grIncident.query();

        while (grIncident.next()) {

                  //apply rule

        }

}

In this example there is a table that defines rules based on condition. It pulls all existing records for that condition and applies the rule.

What if I want to apply the rule to a record that has not been created yet:

var grIncident = new GlideRecord('incident');

grIncident.initialize();

grIncident.field1 = value1;

grIncident.field2 = value2;

...

var grRules = new GlideRecord('rules');

grRules.addQuery('type', 'incident');

grRules.query();

if (grRules.next()) {

        // IF grIncident meets the grRule.condition

              {

                            //apply rule

              }

}

grIncident.insert();

Here I want to see if my new record meets the conditions defined in my rule table. Is there a way to check an encoded query string against a single record?

1 ACCEPTED SOLUTION

Chuck Tomasi
Tera Patron

Hi Aaron,



You're looking for GlideFilter.



Have I got a video for you...


TechNow - Condition Fields


View solution in original post

3 REPLIES 3

Chuck Tomasi
Tera Patron

Hi Aaron,



You're looking for GlideFilter.



Have I got a video for you...


TechNow - Condition Fields


Thanks, that is exactly what I'm looking for.


One of my favorite tools!