- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-30-2014 04:24 PM
Hi Everyone,
I am not sure why this is not working and require some help with this query. I am trying to query name records on a table that are equal to a name field entered by the user on a service catalog item in a Run Script on a workflow.
My script starts as follows which is the part that is not working;
var gr = new GlideRecord('u_contractor_app');
gr.addQuery('u_name', current.variables.u_contractor_name);
gr.query();
gs.log("gr.u_name: " + gr.u_name + " | gr.sys_id: " + gr.sys_id + " current.variables.u_contractor_name: " + current.variables.u_contractor_name); |
When looking at the script log statements gr.u_name and gr.sys_id returns undefined and current.variables.u_contractor_name returns the sys_id of the contractor.
Any help is much appreciated.
Thanks,
Kris
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-30-2014 08:02 PM
As Michael mentioned before, you have to include 'while' or 'if' on your query as like this
var gr = new GlideRecord('u_contractor_app');
gr.addQuery('u_name', current.variables.u_contractor_name);
gr.query();
if(gr.next()){
gs.log("gr.u_name: " + gr.u_name + " gr.sys_id: " + gr.sys_id + " current.variables.u_contractor_name: " + current.variables.u_contractor_name);
}
Thanks,
Anish

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-30-2014 06:05 PM
you need to get the next record after you query the records.
gr.query();
while(gr.next()) {
gs.log("gr.u_name: " + gr.u_name + " | gr.sys_id: " + gr.sys_id + " current.variables.u_contractor_name: " + current.variables.u_contractor_name); |
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-30-2014 08:02 PM
As Michael mentioned before, you have to include 'while' or 'if' on your query as like this
var gr = new GlideRecord('u_contractor_app');
gr.addQuery('u_name', current.variables.u_contractor_name);
gr.query();
if(gr.next()){
gs.log("gr.u_name: " + gr.u_name + " gr.sys_id: " + gr.sys_id + " current.variables.u_contractor_name: " + current.variables.u_contractor_name);
}
Thanks,
Anish

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-01-2014 05:33 AM
Anish
Using an if to fetch the next record will only grab the first record. You need to use a while to grab all records where the contractor name matches the name.
Thanks
Mike