Condition in UI Action to check for "has related child records" ???

Zod
Giga Guru

Hi,

I need to add a UI action on the cmdb_ci_service table that is checking if the record has >0 childs related to serivce offerings ... and wonder about the easy way of doing this ... 

I know there is somethin like ".hasChildren(current.sys_id) ... but this is not specific to service offerings ... so how to specify my "children" here ... ?

 

1 ACCEPTED SOLUTION

You need to configure a script include 

 

function checkIfParent() {

   

var gr = new GlideRecord("cmdb_rel_ci");
gr.addQuery("parent", current.sys_id);
gr.query();

return gr.hasNext()

}

 

In your UI Action, put condition as checkIfParent()

 

View solution in original post

4 REPLIES 4

Shweta KHAJAPUR
Tera Guru

Hi,

try below code in ui action to check has related child records.

 

var parent1=current.sys_id;
var gr = new GlideRecord("cmdb_rel_ci");
gr.addQuery("parent", parent1);
gr.query();
var childs=gr.getRowCount();
if (childs>0) {
    gs.addInfoMessage("child count"+childs);
   
}
else
    gs.addInfoMessage("child count"+childs);
current.update();
action.setRedirectURL(current);

Zod
Giga Guru

... I was looking for a condition it set in the condition field for ui action ... so the UI Action should not show up in case no relevant childs ... 

 

 

 

You need to configure a script include 

 

function checkIfParent() {

   

var gr = new GlideRecord("cmdb_rel_ci");
gr.addQuery("parent", current.sys_id);
gr.query();

return gr.hasNext()

}

 

In your UI Action, put condition as checkIfParent()

 

Shweta KHAJAPUR
Tera Guru

Hi,

Write a script include to check whether that service offering has child or not and then return the result in condition of ui. Call that script include in condition as below

find_real_file.png

 

Please write script include as below,

find_real_file.png