Can we query with catalog item variables while gliding RITM table ?

sr_surendra
Giga Expert

Dear all,

 

I have date field on catalog item form which I want to query with existing date.

For that I tried like below-

var a = new GlideRecord('sc_req_item');

a.addQuery('cat_item.variables.date_variable',gs.now());

a.query();

 

I'm not able to think of some another way to query and this one is not working.

Could someone please help me understanding how we can do this?

 

Regards,

Surendra

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@sr.surendra@tcs 

you can query like this

give the variable sysId there

var a = new GlideRecord('sc_req_item');

a.addQuery('variables.sysId',gs.now());

a.query();

Generic Approach:

You can form the query from the table list and then copy the query and then use it

Select the Variables -> Select your catalog item -> Select your variable -> value to search

For me it looked like this

a.addEncodedQuery('variables.9415cd6f0750ec90540bf2508c1ed042=testing');

find_real_file.png

find_real_file.png

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

5 REPLIES 5

Pranav Bhagat
Kilo Sage

If you want to query 2 tables together do like this

 

var gr = new GlideRecord('table1');
gr.query();
if(gr.next()){

var a = new GlideRecord('table 2');

a.query();

if(a.next()){

}

}

Regards

Pranav

Hi Pranav,

 

Basically requirement is, I have date field on RITM form where user can enter only future dates.

and once that date has reached I want to create new RITM based on current RITM.

 

For that , I'm querying RITM table, querying with that perticular catalog item , and additionally I want to check if that date has reached or not.

 

For that I want to query that date with gs.now

 

can we do it ?

 

Regards,

Surendra

So you are comparing with a already existing ritm with same catalog item.

If that's the case use this script

var gr = new GlideRecord('sc_req_item');
gr.addQuery('cat_item',current.cat_item); //This will filter based on the same item and you can add more query filters
gr.query();
if(gr.next()){
//your code

}

Ankur Bawiskar
Tera Patron
Tera Patron

@sr.surendra@tcs 

you can query like this

give the variable sysId there

var a = new GlideRecord('sc_req_item');

a.addQuery('variables.sysId',gs.now());

a.query();

Generic Approach:

You can form the query from the table list and then copy the query and then use it

Select the Variables -> Select your catalog item -> Select your variable -> value to search

For me it looked like this

a.addEncodedQuery('variables.9415cd6f0750ec90540bf2508c1ed042=testing');

find_real_file.png

find_real_file.png

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader