Populate list of child values from relationship table filtering condition in name of catalog

DhanashriP
Tera Contributor

Hi,

 

I want to Populate list of child values from relationship (cmdb_rel_ci) table filtering condition ()in "vm name" variable of catalog item, which is reference field refers to "cmdb_ci_vmware_instance" table(this is referring to the instance table because I want to filter all the vm name which has relationship where type is "Provides storage for::Stored on " and Parent does not contains Placeholder).

I have tried using Script include and called the same in "vm name" variable's reference qual as "javascript:getvm()".

this is not working looking for help.

 

Script include:

var getVM = Class.create();
getVM.prototype = {
initialize: function() {},
getVM: function() {
gs.log("In function");
var option = [];
var nameArray = [];
var flag = new GlideRecord('cmdb_rel_ci');
flag.addEncodedQuery('parentNOT LIKEPLACEHOLDER^type!=c6fd799338a02000c18673032c71b81d');
flag.query();
while (flag.next()) {
option.push(flag.getDisplayValue('child'));
}
gs.log("childArrya"+ option);
var vmwareResponse = new GlideRecord('cmdb_ci_vmware_instance');
vmwareResponse.addQuery('name', 'IN', option);
vmwareResponse.query();
while (vmwareResponse.next()) {
nameArray.push(vmwareResponse.name.toString());
}
return nameArray;

},
type: 'getVM'
};

 

DhanashriP_0-1723618630763.png

 

DhanashriP_1-1723618630695.png

 

 

1 REPLY 1

Bhavya11
Kilo Patron

Hi @DhanashriP ,

 

 

if you returning the name in reference qualifier you need to update like as below

javascript:'nameIN'+new getVM().getVM()

 

if you returning sys_id in  reference qualifier you need to update like as below

javascript:'sys_idIN'+new getVM().getVM()

 

 

 

Please mark helpful & correct answer if it's really worthy for you.

 

Thanks,

BK