How to show reference field values based on selection of the record

Gopal14
Tera Contributor

Hi Team,

 

I am having 2 reference Variables.

1. Serial Number (alm_hardware table)

2. Hardware item (cmdb_hardware_product_model table)

 

In serial number if I select any record for that record we have model category. Let take I have selected 'Lenovo' for this record model category is "personal computer". 

In Hardware Item Variable, I need to show on "personal computer" model category only.

1 ACCEPTED SOLUTION

Hi @Gopal14 ,

Your client script seems to be having issue, please try the below one :

Client script:

function onChange(control, oldValue, newValue, isLoading) {

    if (isLoading || newValue === '') {

        return;

    }

    var ga = new GlideAjax('GetProductModelBySerial');

    ga.addParam('sysparm_name', 'getProductModel');

    ga.addParam('sysparm_serial_number', newValue);
    ga.getXML(getProductModelParse);

    function GetDFcabParse(response) {
        var answer = response.responseXML.documentElement.getAttribute("answer");
        console.log(answer);
        g_form.setValue('hardware_item_variable', answer);

    }

}

Script Include:
Use the same one which you have created.

You can check whether you are getting the value in console of the browser which can be accessed by pressing Ctrl+shift+i and clicking console tab, search for the model name to see if it printed it or not.

Please mark my answer "Helpful" and "correct" if you feel that it has helped you in any way.

Thanks and Regards,
K. Sai Charan
Sr. ServiceNow Developer
Deloitte India

View solution in original post

15 REPLIES 15

Hi @Gopal14 ,

Did you try checking what you are getting in console logs ? If so what did you get in it

 

Hi @Sai_Charan_K 

 

Gopal14_0-1727247159896.png

 

Gopal14_1-1727247193996.png

 

Gopal14_2-1727247224894.png

 

 

Hi @Gopal14 ,

Please find the scripts below:

Onchange Client script:

 

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    var ga = new GlideAjax('GetProductModelBySerial');
    ga.addParam('sysparm_name', 'getProductModel');
    ga.addParam('sysparm_serial_number', newValue);
	alert(newValue);
    ga.getXML(getProductModelParse);

    function getProductModelParse(response) {
        var answer = response.responseXML.documentElement.getAttribute("answer");
        //console.log("Hi "+answer);
        g_form.setValue('hardware_item', answer);

    }
}

 

 


Script Include: Please make sure this is client callable

 

 

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

    getProductModel: function() {
        var serialNumber = this.getParameter('sysparm_serial_number');
        //gs.log("Hi" + serialNumber);
        var assetGR = new GlideRecord('alm_asset');
        assetGR.addQuery('sys_id', serialNumber);
        assetGR.query();
        if (assetGR.next()) {
            gs.log("Hi " + assetGR.model);
            return assetGR.model.sys_id;
        }
        return '';
    },
    type: 'GetProductModelBySerial'
});

 

 


PFA screenshots. 

Please mark my answer "Helpful" and "correct" if you feel that it has helped you in any way.

Thanks and Regards,
K. Sai Charan
Sr. ServiceNow Developer
Deloitte India

 

HI @Sai_Charan_K 

 

Updated in same way which you have given.

 

Not working, logs are not coming syslog_list table.

 

Gopal14_0-1727253708626.png

 

Gopal14_1-1727253729968.png

 

 

Script Include:

Gopal14_2-1727253780233.png

 

Client Script:

Gopal14_3-1727253819697.png

 

In client check variable name for hardware item