Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

addQuery() is not returning any records even though I can find the record manually

123456789456123
Kilo Contributor

So,

I am doing this out of a workflow script:

var gr = new GlideRecord('table');

gr.addQuery('requested_item', current.number) //current.number is the correct RITM that I am expecting

gr.query();

//here's where I scratch my head

if (gr.next()) {

        gs.info('found record with ritm: ' + current.number);

        gr.setValue('status', 2);

        gr.update();

}

else {

        gs.info('could not find record');

}

This is returning the "could not find record" in the logs. But when I go to the table and manually add the filter:

requested item , is, RITMXXXXX

It pulls up the record I am searching for. So I know this means my query must be off but I'm not sure where / how. Could anyone help me out?

Thank you.

1 ACCEPTED SOLUTION

replace your addQuery with following


gr.addQuery('requested_item.number', current.number);



(;) is missing in your addQuery


View solution in original post

14 REPLIES 14

wadeb
Giga Contributor

Hello.   I usually put an operator in my addQuery tag.   You might try adding ",'='" in between the two parameters.   See below.  



gr.addQuery('requested_item', '=', current.number)


Same message. It came up empty.


sushant007
Kilo Guru

not sure if this is solution to your issue or not:


var gr = new GlideRecord('table');



here first replace 'table' to correct table name



and replace your addQuery with following


gr.addQuery('requested_item.number', current.number)


wadeb
Giga Contributor

Ben,


I looks like your first list is not specifying what table to query.   You have "var gr = new GlideRecord('table'); "   you will need to specify what table to query.   Below is an example for querying the "Requested Item" table



var gr = new GlideRecord('sc_req_item');