The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Related List to display all affected CI records

harishdasari
Tera Guru

Hi,

In change request, when user adds additional CI's in related list affected CI tab, Then it should fetch all the records like incident, Problem, change and it should get displayed in the newly created section called "Related affected CI record".

any one please let me know how can I achieve this

Thank you

Michael.Fry   kalai

10 REPLIES 10

Hi Abhinay,



Thankyou for responding to my post



my requirement is, to display incident, problem, change records, when user manually add affected CI's as shown in screenshot.



For example : here user selected the Infoblox in affected CI related list, now it should fetch all the records of infoblox under a section called "Related CI records".


This section is created using the "Relationships" which queries from task_ci table and displays on change table



find_real_file.png



Thank you.


I am not infront of my computer right now. But this is how your script will look like


After business rule on task_ci table


When: after insert


Filter Conditions: task.type is change request(assuming you only want this on change). AND task is not empty


Script:


var gr=new GlideAggregate('task_ci');


gr.addQuery('field name of ci on the task_ci table', current.getValue('field name of ci'));


gr.addQuery('sys_id', '!=', current.getValue('sys_id'));


gr.addQuery('task','!=', current.getValue('task'))(


gr.groupBy('task');


gr.query();


while(gr.next()){


//insert your records in to that table here


//you may also want to check if that task record is already inserted, so that you don't end up with dups


}






Hi Abhinay,



I have fallowed your suggestions, But I am not sure, it is fetching all the records of different configuration item.



var gr=new GlideAggregate('task_ci');


gr.addQuery('ci_item', current.getValue('cmdb_ci'));


gr.addQuery('sys_id', '!=', current.getValue('sys_id'));


gr.addQuery('task','!=', current.getValue('task'));


gr.groupBy('task');


gr.query();


while(gr.next()){



var gr1 = new GlideRecord('task_ci');


gr1.addQuery('task',current.sys_id);


gr1.query();


if(gr1.next())


{


gr1.task   = gr.task;  


gr1.cmdb_ci = gr.cmdb_ci;


gr1.update();


}


else


{


gr1.initialize();


gr1.task   = gr.task;  


gr1.cmdb_ci = gr.cmdb_ci;


gr1.insert();


}



This is the code I am using in Business rule. But nothing is displaying in the newly created relationship tab called "related records".



Can you pls help me.


Use this code



                              var gr=new GlideAggregate('task_ci');


                              gr.addQuery('ci_item', current.getValue('ci_item'));


                              gr.addQuery('sys_id', '!=', current.getValue('sys_id'));


                              gr.addQuery('task','!=', current.getValue('task'));


                              gr.groupBy('task');


                              gr.query();


                              while(gr.next()){


                                                              var gr1 = new GlideRecord('your related task table name');


                                                              gr1.addQuery('<task field name on this custom table>', gr.<task field name on this custom table>);


                                                              gr1.addQuery('field name of ci', gr.getValue('ci_item'))


                                                              if(!gr1.next()){


                                                                                              gr1.<task field name on this custom table>=gr.getValue('task');


                                                                                              gr1.<field name of ci>=gr.getValue('ci_item');


                                                                                              gr1.insert();


                                                              }


                              }


How did this go? If I have answered the question, please mark it as correct or else let me know if you have any further questions on this.