Auto Poupulate the asset assigned to the user

Aruna13
Tera Contributor

Hi,

 

I have the catalog form where there are 2 reference fields.

1. user_to_be_released - reference of sys_user table

2. computer_name - reference of alm_hardware table

 

Now i need to auto populate the asset assigned to the user( "user_to_be_release field") in computer_name field  and below are the CS and script include which i have written. But i didnt get any values returned in computer_name field.

Can you please help me with this and is there any reference qualifier needs to added in computer_name field? Please give your suggestions, since i am new to scripting.

 

Client Script - written on computer_name and type is onChange

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

    // Client script for auto-populating computer name on change
    var ga = new GlideAjax('GetAssetName');
    ga.addParam('sysparm_name', 'getAssetName');
    ga.addParam('sysparm_req', newValue);
    ga.getXML(GetAssetNameParse);
 
    function GetAssetNameParse(response) {
    var answer = response.responseXML.documentElement.getAttribute("answer");
    g_form.setValue('computer_name', answer);

    }

 

Script Include - client callable

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

    getAssetName: function() {
        var req = this.getParameter('sysparm_user_to_be_released');
        var gr = new GlideRecord('alm_hardware');
        gr.addQuery('assigned_to', req);
        gr.addQuery('model_category','Computer');
        gr.query();
        if (gr.next()) {
            return gr.asset_tag; // returning the sys_id ensures that all fields in the reference are retrieved
        }
    },
    type: 'GetAssetName'

});

 

 

18 REPLIES 18

Hi @Aruna13,

 

Please please change the variable name on client script as user field then it will work because you are changing the user name in field and variable name field is variable name itself.

 

Please accept my solution if it works for you and thumps up.

 

Thanks

Jitendra

Please accept my solution if it works for and thumps up.

@Jitendra Diwak1 sorry, I am not getting your correction here. Can you explain me which line of code i have to change and what to change. Apologies for multiple questions, since i am new to scripting.

 

Thanks

Hi @Aruna13,

 

Please change variable as USER  as per the below screenshot:

 

JitendraDiwak1_0-1717062009430.png

 

Please accept my solution if it works for you and thumps up.

 

Thansks

Jitendra

Please accept my solution if it works for and thumps up.

Aruna13
Tera Contributor

@Jitendra Diwak1 @Ankur Bawiskar 

 

I just found that there is another Catalog client script written for the "user_to_be_released"  which is auto populating other fields like email, manager(these are catalog variables)

etc. When i change the variable name in my Client Script to  "user_to_be_released", the other fields are not populating as expected. What could be the issue here? Cant we have two catalog client script written for one variable?

if it has to be only one, then how should i put it?

 

existing CS:

Aruna13_0-1717064814062.png

 

can you please check and let me know what is the issue here and guide me