- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-16-2015 11:19 AM
Hello,
I am currently trying to figure out how to query between related tables, such as chg requests and tasks. This is what I am attempting:
var gl = new GlideRecord('change_task');
var glC = gl.addJoinQuery('change_request');
glC.addCondition('number','CHG0031079');
gl.query();
while(gl.next()){
gs.print(gl.number);
}
But this just returns every change task in the system. What am I missing/misunderstanding with how to use the join functionality and query apppropriately?
Best regards,
Brian
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-16-2015 11:36 AM
Ah ok I figured it out, it looks like it has to join specifying the change_request as the joining field on change_task, and sys_id on change_request. Thank you for the help Suraj it definitely pointed me in the right direction!
var gl = new GlideRecord('change_task');
var glC = gl.addJoinQuery('change_request','change_request','sys_id');
glC.addCondition('number','CHG0031079');
gl.query();
while(gl.next()){
gs.print(gl.number);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-16-2015 11:25 AM
Hi Brian,
Change request and Change task are linked with the change_request field on the change task form.
Can you try this ?
var gl = new GlideRecord('change_task');
gl.addCondition('change_number','CHG0031079');
gl.query();
while(gl.next()){
gs.print(gl.number);
}
Suraj Chauhan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-16-2015 11:31 AM
Hi Suraj,
I just tried that but it looks like I am getting the same results where it lists every change task.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-16-2015 11:36 AM
Ah ok I figured it out, it looks like it has to join specifying the change_request as the joining field on change_task, and sys_id on change_request. Thank you for the help Suraj it definitely pointed me in the right direction!
var gl = new GlideRecord('change_task');
var glC = gl.addJoinQuery('change_request','change_request','sys_id');
glC.addCondition('number','CHG0031079');
gl.query();
while(gl.next()){
gs.print(gl.number);
}