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

Can we connect in Google meet if you are available?

Meeting code is tqnxopkjnpq

Yes

Tai Vu
Kilo Patron
Kilo Patron

Hi @Gopal14 

Let's give the Auto-populate feature within the variable a try. And you can autofill the Hardware Model (or Model Category) based on the selected Hardware (with Serial Number) without a line of code.

Timi_0-1727243743963.png

 

Cheers,

Tai Vu

Amit Verma
Kilo Patron
Kilo Patron

Hi @Gopal14 

 

The easiest way to do this is using the Auto-Populate feature for reference variables. Refer below steps :

 

1. Suppose you have 2 reference variables as shown below :

 

Serial Number which refers to alm_hardware table and Hardware item which refers cmdb_hardware_product_model table

 

AmitVerma_2-1727248525591.png

 

AmitVerma_3-1727248539627.png

 

2. While configuring the Hardware Item variable, you can make use of Auto-Populate tab as shown below :

AmitVerma_4-1727248598360.png

 

Output -

AmitVerma_5-1727248625614.png

 

Thanks and Regards

Amit Verma


Please mark this response as correct and helpful if it assisted you with your question.

Hi @Amit Verma 

 

In Hardware Item variable I need entire list of model categories, so that user will select what ever they want from the list