Some PDIs are currently unavailable, and PDI actions are paused. View the latest updates here. Read More

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

Ankur Bawiskar
Tera Patron

@nishanthip 

if it worked fine before, then what changed recently?

what debugging did you do?

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

yashkamde
Giga Sage

Hello @nishanthip ,

 department: userGr.department.toString(),
 email: userGr.email.toString()

Here try removing .toString() & user "userGr.getDisplayValue('department')"..

Also there can we issue with newvalue according to me try instead g_form.getValue('caller_id').
OLD----> ga.addParam('sysparm_caller_id',newValue);
Replace ----> ga.addParam('sysparm_caller_id',g_form.getValue('caller_id'));

 


If my response helped mark as helpful and accept the solution

Aditya_hublikar
Giga Sage

Hello @nishanthip ,

 

Your all script seems fine .You are saying it was working fine before and now its not working , can you please once check in script include there is any change done . Glide ajax callable checkbox is checked ? Its accessible from all application scope ? may be here  in ga.addParam('sysparm_caller_id',newValue); newvalue dont getting valid data  can you please also check this by g_form.addInfoMessage(newValue) ; 

what value is getting stored in newValue. You can also try g_form.getValue('caller_id') instead of newValue here ga.addParam('sysparm_caller_id',newValue;  

This can be also reason if ACLs changed recently, the Script Include may not be allowed to read:

  • sys_user.department

  • sys_user.email

Also Try this :

g_form.setValue('u_department', data.department || '');
g_form.setValue('u_email_id', data.email || '');

Also check user that you are selecting he had valid email and department or not .

 

If this helps you then mark it as helpful and accept as solution.

Regards,

aditya

Hello @nishanthip ,

 

 I hope you are doing well . Does my response helps you ?