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.

Help creating Related List on cmdb_ci that queries change request where any affect ci is included

Jordan_M
Giga Expert

Hey all!

 

I am running into an issue trying to create a related list on the cmdb_ci table that references change_request. I have the relationship created but can't get a script to work that successfully queries task_ci. The requirements are - Related list on cmdb_ci to show change requests where the current CI Record is an affected ci on a change.

 

I have been able to get it to work by directly going to task_ci but they need the fields from Change showing not the fields from task_ci.

 

My current code looks like -

(function refineQuery(current, parent) {

current.addQuery('RLQUERYtask_ci.ci_item', parent.sys_id);

})(current, parent);

 

This returns all change records, not filtered in any way. Any suggestions or input is greatly appreciated!

1 ACCEPTED SOLUTION

Jordan_M
Giga Expert

This works if anyone comes across the same question later -

 

(function refineQuery(current, parent) {
var chgs = [];
var gr = new GlideRecord("task_ci");
gr.addQuery("ci_item", parent.sys_id);
gr.addEncodedQuery('taskSTARTSWITHchg');
gr.query();

while(gr.next())
chgs.push(gr.getValue("task"));

current.addQuery('sys_id', 'IN', chgs.join());

})(current, parent);

View solution in original post

2 REPLIES 2

Jordan_M
Giga Expert

I have also tried doing a GlideRecord and join with the same results - 

 

(function refineQuery(current, parent) {
var chgs = [];
var gr = new GlideRecord("task_ci");
gr.addQuery("ci_item", current.sys_id);
gr.addEncodedQuery(taskSTARTSWITHchg);
gr.query();
var count = 0;
while(gr.next())
chgs.push(gr.getValue("change_request"));

current.addQuery('sys_id', 'IN', chgs.join());

})(current, parent);

Jordan_M
Giga Expert

This works if anyone comes across the same question later -

 

(function refineQuery(current, parent) {
var chgs = [];
var gr = new GlideRecord("task_ci");
gr.addQuery("ci_item", parent.sys_id);
gr.addEncodedQuery('taskSTARTSWITHchg');
gr.query();

while(gr.next())
chgs.push(gr.getValue("task"));

current.addQuery('sys_id', 'IN', chgs.join());

})(current, parent);