Auto populate fields does not work on Service Portal

Ankita Gupte
Kilo Sage

Hello I have written below onChange Client script to Auto Populate variable based on "Name"

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var caller = g_form.getReference('Name', doAlert); // doAlert is our callback function
}

function doAlert(caller) { //reference is passed into callback as first arguments

g_form.setValue('var_title', caller.title);
g_form.setValue('var_department', caller.department);
g_form.setValue('var_manager_name', caller.manager);
g_form.setValue('var_comp', caller.company);
g_form.setValue('var_location', caller.location);

var site_val = caller.location;

var loc_gr = new GlideRecord('cmn_location');
loc_gr.addQuery('sys_id', site_val);
loc_gr.query();

while (loc_gr.next()) {
g_form.setValue('var_city', loc_gr.city);
g_form.setValue('Country', loc_gr.country);

}
}

Its auto populating city and country on Fulfiller portal based on Name selected when we navigate from maintain items -> open catalog item and use try it option.

But when I check same on service portal its empty

FYI, The user form has location information and when open record for location i.e. location form has city and country information.

Kindly advice, let me know if any more information required to look into the same.

6 REPLIES 6

Murthy Ch
Giga Sage

Hi @Ankita Gupte 

Ensure UI type- ALL 

GlideRecord is not recommended in client side. Use Script Include and GlideAjax call.

Thanks,
Murthy

Yes the UI type is ALL.

Can you guide me with script include and glide ajax call.

Hi @Ankita Gupte 

Try something like below:

On change client script on Name

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

    var abc = new GlideAjax('Getuserdetails'); // script include name
    abc.addParam('sysparm_name', 'getUserdata'); //function name
    abc.addParam('sysparm_requestedfor', newValue); //pushing user sysID into server side
    abc.getXML(callbackdata);

    function callbackdata(response) {
        var answer = response.responseXML.documentElement.getAttribute("answer");
        var push = answer.split('!'); //setting user details into variables
        g_form.setValue('var_title', push[0]);
        g_form.setValue('var_department', push[1], push[2]); //setting both value and display value
        g_form.setValue('var_manager_name', push[3], push[4]);
        g_form.setValue('var_comp', push[5], push[6]);
        g_form.setValue('var_location', push[7], push[8]);
        g_form.setValue('var_city', push[9]);
        g_form.setValue('Country', push[10]);
    }
}

Create a client callable script include:

var Getuserdetails = Class.create();
Getuserdetails.prototype = Object.extendsObject(AbstractAjaxProcessor, {
 getUserdata: function() {
        var grU = new GlideRecord('sys_user');
        grU.addQuery('sys_id', this.getParameter('sysparm_requestedfor'));
        grU.query();
        if (grU.next()) {
            return grU.title + '!' + grU.department + '!' + grU.department.getDisplayValue() + grU.manager + '!' + grU.manager.getDisplayValue() + '!' + grU.company + '!' + grU.company.getDisplayValue() + '!' + grU.location + '!' + grU.location.getDisplayValue() + '!' + grU.location.city + '!' + grU.location.country;
        }
    },
    type: 'Getuserdetails'
});

If you are new to the GlideAjax concept. Refer my Article

Hope it helps

 

Thanks,

Murthy

Thanks,
Murthy