Run an encoded query on a current glide record object

Toren
Kilo Guru

Hi All!

It is way too long a story to explain why I need this, but I am looking for a function or something that can run and encoded query against a retrieved gliderecord object to see if it meets the criteria of the the encoded query.

 

Doing this in a widget in service portal.

 

I hope I am explaining that well if not here is code to try to help explain what I need:

 

var gr = new GlideRecord("table_name");

gr.get("342sysid54325");

var boolean = gr.EncodedQueryFunctionThatINeed("active=true^short_description=hellothere^name=yo"); // <---- THE FUNCTION I NEED

if (boolean) {

console.log("The Record is Active, has a short description of hellothere and is named yo");

} else {

console.log("The Record is either not Active, does not have a short description of hellothere  or is  not named yo");

}

1 ACCEPTED SOLUTION

Toren
Kilo Guru

Found out a solution a while back. Just create a new GlideRecord object with the encoded query and the sys_id of the current record you want to check, query the table using the new glide record, and see if it gets an entry back. If it does, it is your record and it matches the query you wanted to check it against. 

View solution in original post

6 REPLIES 6

Can you explain bit more on this? I am trying to do same for catalogs but unable to get current records encoded query in a client script... Appreciate your help.

Sure! This is a simplish coded example of what i did

 

//This is the sys id of the record I want to check

var sysID = '1234567';

//Glide record for the table that the record resides on

var gr = new GlideRecord("table_name");

//Add the sys id to the encoded query that I wanted to check against the record

gr.addEncodedQuery("sys_id="+ sysID +"active=true^short_description=hellothere^name=yo");

//Query the table

gr.query();

/*If the glide record finds a record then it is the record that has the SYS ID and matches the encoded query. Thus the record matches the encoded query*/

if (gr.next()) {

console.log("The record with sys id 1234567 matches the encoded query of active=true^short_description=hellothere^name=yo");

}

 

Hope that helps!