Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

How do I find the associated change tasks of a change request via Glide scripts?

bcronrath
Kilo Guru

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

1 ACCEPTED SOLUTION

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);



}


View solution in original post

3 REPLIES 3

User179407
Mega Guru

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


Hi Suraj,


I just tried that but it looks like I am getting the same results where it lists every change task.


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);



}