Looking to populate a set of Child records from CI relationship table in the catalog variable.

___15
Giga Contributor

I want to populate a set of Child records from the CI Relationship table in a "Reference" type catalog variable. There is a "Application Name" variable on a catalog form referring to Parent field of CI Relationship table and there is another catalog variable "Database" referring to "Child" field of CI relationship table. I need all the child values in "Database" field corresponding to the values selected in "Application Name" field. One Parent has multiple associated child in CI Relationship table. I created a script include to use in reference qualifier for "Database" field to meet the requirements but its giving me all the Child records and i need only specific to the values selected in "Application Name" field.

 

Reference Qualifier:  javascript: new OracleParent().findRelationships(current.variables.application_name)

Script Include:  

 

var OracleParent = Class.create();
OracleParent.prototype = {
    initialize: function() {
    },
    findRelationships: function(parent)
    {
      
        if(parent == "")
        {
            return "sys_idIN0000000000";
        }
        var rel = new GlideRecord('cmdb_rel_ci');
        var arrRel = [];
        rel.addQuery('parent', parent);
        rel.query();
        while(rel.next())
        {
                   
                        arrRel.push(rel.sys_id.toString());
        }
       
        
        var ans = "parent.nameIN";
        for(var a = 0; a < arrRel.length; a++)
        {
            if(a > 0)
            ans = ans + ",";
            ans = ans + arrRel[a];
           
        }
        return ans;
    },
   
    type: 'OracleParent'
};
0 REPLIES 0