Auto update the department and email ID.

nishanthip
Tera Contributor

Auto field update based on the caller ID. It was working fine before but i am not what went wrong it is not working now.

Please someone help.

 

Client Script:

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

    var ga = new GlideAjax('GetUserDetails');
    ga.addParam('sysparm_name','getDetails');
    ga.addParam('sysparm_caller_id',newValue);
    ga.getXMLAnswer(function(response) {
        var data = JSON.parse(response);
        g_form.setValue('u_department',data.department);
        g_form.setValue('u_email_id',data.email);
    });
}
 
Script Include:
var GetUserDetails = Class.create();
GetUserDetails.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    getDetails: function() {
        var callerId = this.getParameter('sysparm_caller_id');
       
        var userGr = new GlideRecord('sys_user');
        if (userGr.get(callerId)) {
            var data = {
                department: userGr.department.toString(),
                email: userGr.email.toString()
            };
           
            return JSON.stringify(data);
        }

        return JSON.stringify({});
    },

    type: 'GetUserDetails'
});
5 REPLIES 5

Hi @Aditya_hublikar , Thank you so much for your response. I made a mistake while creating reference field. I used below code to get auto populate Email, location, department now working fine. 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if(isLoading){
        g_form.setValue('u_caller',g_user.userID);
    }


   if (newValue === '') {
    g_form.clearValue('u_department');
    g_form.clearValue('u_location');
    g_form.clearValue('u_e_mail');
    return;
   }

   var store = g_form.getReference('u_caller',function(callBack) {
    g_form.setValue('u_department',callBack.department);
    g_form.setValue('u_location',callBack.location);
    g_form.setValue('u_e_mail',callBack.email);

   });
}