auto populate list collector variable value in service catalog

v-paulp
Tera Contributor

Hi 

I want to auto populate one list collector variable value based on the value selected to other variable.

I have written one script include and client script but it is returning null value.

vpaulp_0-1719773656504.png

 

script include 

var getuserreports = Class.create();
getuserreports.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    getreportsname: function() {
        var reportsname = [];
        var ownername = this.getParameter('sysparm_owner');
        var gr1 = new GlideRecord('sys_report');
        gr1.addEncodedQuery('created_by_user',ownername);
        gr1.query();
        while (gr1.next()) {
            reportsname.push(gr1.title.toString());
        }
        return reportsname.join(',');
    },

    type: 'getuserreports'
});
 
 
client script
 
function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }

    var report_owner = g_form.getDisplayValue('owner_of_the_report');
    alert(report_owner);
    var gr = new GlideAjax('getuserreports');
    gr.addParam('sysparm_name', 'report_names');
    gr.addParam('sysparm_owner', newValue);
    gr.getXML(getResult);

    function getResult(response) {
        var answer = response.responseXML.documentElement.getAttribute("answer");
        alert(answer);
    }
}
 
Am  I doing anything wrong ?
3 REPLIES 3

SwapnilKumar
Tera Contributor

Hi 

i could see that the function name in client script is incorrect, you should pass sysparm_name as getreportnames in client script also if the field which you are trying to populate is a reference field then you may to return sysids instead of title.

 

 Thanks 

Hi @SwapnilKumar , 

Now it is returning the arr but on list collector variable value is  not populating automatically, I have use g_form.setValue() to auto fill the variable value but it is not auto filling.

Do I need to use any other method for this?

 

Alp Utku
Mega Sage

You could achieve this by using Data Lookup Rules for Catalog Items. However, you need to create a backup table to hold relationship between variables.