- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-07-2017 06:05 AM
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.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-07-2017 06:30 AM
replace your addQuery with following
gr.addQuery('requested_item.number', current.number);
(;) is missing in your addQuery
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-07-2017 06:28 AM
In my script I have the table name. I left it out because it was rather long..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-07-2017 06:30 AM
replace your addQuery with following
gr.addQuery('requested_item.number', current.number);
(;) is missing in your addQuery
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-07-2017 06:48 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-07-2017 07:01 AM
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)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-07-2017 07:05 AM
Thanks for writing it down David; because I was about to start writing this explanation