Filter Variable based on a reference Field

Xion
Tera Expert

I have a Variable named 'var A' in the Variable set referencing the company table.

I have a field on the Incident table named 'Fil A' which again refrences the company table.

 

Now what I want is, whatever the Value is selected in the Field 'Fil A', I want to show these values in Variable 'Var A' in a Variable set. 

Please help with the response.

 

Thanks

Xion

 

 

5 REPLIES 5

Okay, in this case, you have a variable 'Var A' referencing the Company table and a filed 'Fil A' on the Incident table referencing the Company table.

 

As you are relating the var A and Fil A, I assume there is an another variable on Catalog item referncing to the incident table and based on selection of the Incident, you need to populate the Fil A data into Var A.

 

You can try with GlideAjax as below.

 

Onchange Client Script:

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

    var ga = new GlideAjax('global.CatalogUtils');
    ga.addParam('sysparm_name', 'getIncidentCompany');
    ga.addParam('sysparm_incident', newValue);
    ga.getXML(callBack);

    function callBack(response) {
        var answer = response.responseXML.documentElement.getAttribute("answer");
        g_form.setValue('company', answer);
    }
}

 

Script Include:

var CatalogUtils = Class.create();
CatalogUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    getIncidentCompany: function() {

        var incidentId = this.getParameter('sysparm_incident');

        var grInc = new GlideRecord("incident");
        if (grInc.get(incidentId)) {
            gs.log("Sunil Incident compamny is - " + grInc.company);
            return grInc.company;
        } else {
            return '';
        }
    },

    type: 'CatalogUtils'
});

 

SunilKumar_P_0-1704507893246.pngSunilKumar_P_1-1704507922776.png

SunilKumar_P_2-1704507972607.png

 

Regards,

Sunil