Autopopulate email,location,manager of caller onchange client script

Community Alums
Not applicable

Hi,

I am trying to populate email,location , manager name of caller on change client script,

Unfortunately its not working.

 

Client script - 

 

function onChange(_control, _oldValue, newValue, isLoading, _isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }
    var callerdetails = g_form.getValue('caller_id');


    var ga = new GlideAjax('getEmailID');
    ga.addParam('sysparm_name', 'emaildetails');
    ga.addParam('sysparm_value', callerdetails);
    ga.getXML(getResult);

    function getResult(response) {
        var answer = response.responseXML.documentElement.getAttribute('answer');
   

        var demo = answer.split(',');
        g_form.setValue('email',demo[0]);
        g_form.setValue('manager',demo[1]);
        g_form.setValue('location',demo[2]);
    }

}
 
 
Script Include:
 
var getEmailID = Class.create();
getEmailID.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    emaildetails: function() {
        var test = this.getParameter('sysparm_value');
        gs.log('testshubham', test);
        var xe = new GlideRecord('sys_user');
        xe.addQuery('sys_id', test);
        xe.query();
        if (xe.next()) {
            gs.log('email is ' + xe.email + ',' + xe.manager + ',' + xe.location);
            return xe.email + ',' + xe.manager + ',' + xe.location;
        }
                return '';

    },


    type: 'getEmailID'
});
6 REPLIES 6

Mark Manders
Mega Patron

Where? Is this for a catalog item/record producer? Use 'auto populate' and you won't have to fill anything through script. It will just get the information from the user record.

Is it on a record in the backend? Use dot walked fields, so you get the information directly from the user table. 

 

No need for any scripting anymore.


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

Hi @Mark Manders,

 

I am not sure if auto-populate works for auto-populate. I tried it long back and it didn't work.

 

Regards

Suman P.

Then it wasn't configured correctly, because I am always using this since it was introduced. Auto populate works for auto populate, because that's what it was designed for.

You create the location variable and set the auto populate to be depending on the user variable and select the location field (and same for the others). 
Just select the user and the other fields are auto populated.


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

Thank you @Mark Manders,

 

I will try to do it on my Personal Developer Instance. I will ask for your help if needed.

Regards

Suman P.