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

In my script I have the table name. I left it out because it was rather long..


replace your addQuery with following


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



(;) is missing in your addQuery


This was the answer. requested_item was not the field. Even though I right clicked on the field and it said it was requested_item. When I changed it to requested_item.number it worked. Thank you.


Hi Ben,



Just for clarity, the field was called requested_item but if it's a reference field it's value will be the sys_id of of the record it is referencing.



The reason your query didn't work is because you were matching a sys_id with a number (D972ca208dbdf36003f5f76100f9619b2, RITM12345689). With Sushants solution you are matching the number field of the requested_item with the number of the current record, alternatively you could have matched requested_item with current.sys_id (or just current)


Thanks for writing it down David; because I was about to start writing this explanation