Based on selection, populate related list (child tab) of software applications

Bindhu1
Tera Contributor

Hi,

I have a  requirement  to one of the catalog items for the persona selected ,populate the related list (child tab) of software applications for user guidance.

refer the screenshot 

here the field refers to custom table 'u_vdi_image' when user selects 'Architecture 2018/2019 (ARC1819)' , there is new variable that should show the related list of child tab. how to achieve this kindly help me with code, thanks.

Bindhu1_0-1706614428081.png

Bindhu1_2-1706615042471.png

child tab refers to cmdb_rel_ci table.

Bindhu1_1-1706614897751.png      

 

 

5 REPLIES 5

Anil Lande
Kilo Patron

Hi,

You can use reference qualifier for your Variable that show the list for Childs.

You can add condition like below:

javascript: 'parent='+current.variables.softaware_architecture.toString()

 

Replace the name of your softaware_architecture variable in above.

 

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

Hi Anil , thanks for replying 
here new variable which shows the list of child record should be read only . i am not even sure which data type to select for this variable , please let me know if u have idea.

Mark Manders
Mega Patron

I guess you will need a catalog client script and a script include.

Try it with something like this (you may need to tweak it):

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue === '') {
        return;
    }

    // Clear the child_ci choice field first
    g_form.clearOptions('child_ci');

    // Call the server to get the related child CIs
    var ga = new GlideAjax('GetChildCIsAjax');
    ga.addParam('sysparm_name', 'getChildCIs');
    ga.addParam('sysparm_parentCI', newValue);
    ga.getXMLAnswer(function(response) {
        var childCIs = JSON.parse(response);
        childCIs.forEach(function(ci) {
            g_form.addOption('child_ci', ci.sys_id, ci.display_value);
        });
    });
}

 

var GetChildCIsAjax = Class.create();
GetChildCIsAjax.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    getChildCIs: function() {
        var parentSysId = this.getParameter('sysparm_parentCI');
        var childCIs = [];

        // Query the cmdb_rel_ci table to find related child CIs
        var relGR = new GlideRecord('cmdb_rel_ci');
        relGR.addQuery('parent', parentSysId);
        relGR.query();
        while (relGR.next()) {
            var childCI = {};
            var ciGR = new GlideRecord('cmdb_ci');
            if (ciGR.get(relGR.child)) {
                childCI.sys_id = ciGR.sys_id.toString();
                childCI.display_value = ciGR.getDisplayValue();
                childCIs.push(childCI);
            }
        }

        return JSON.stringify(childCIs);
    }
});

 


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

Hi Mark , thanks for replying 
here new variable which shows the list of child record should be read only . i am not even sure which data type to select for this variable , please let me know which data type u are referring for child_ci .