The CreatorCon Call for Content is officially open! Get started here.

How to get the requested for supervisor to populate a variable using a catalog client script

Rhonda9
Tera Expert

Hello, 

 

I created a client script to auto populate the supervisor_email variable.  It is populated the requested for email instead of the requested for supervisor email.  I'm not sure what I am doing wrong.  Here is a copy of my script...  Any help would be appreciated...

 

function onChange(control, oldVlue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
 
var requestdFor = g_form.getReference('requested_for', setEmail);
 
function setEmail(requestedFor) {
if (requestedFor) g_form.setValue('account_docusign_supervisor_email', requestedFor.manager.email);
}
 
}

Rhonda9_0-1699565482689.png

 

 

3 REPLIES 3

Brad Bowman
Kilo Patron
Kilo Patron

Hi Rhonda,

This is the same scenario as your previous inquiry.  getReference will only return the field values of fields on the referenced table, not field values on any referenced fields of those fields, so use GlideAjax to get the email of the manager.

Thank you, I will give it a try.

Shubham Singh
Mega Guru

Hi @Rhonda9 

getReference() can be used to fetch the fields on the Referenced table only. Double dot-walking will not work here.

You have to user GlideAjax() API to fetch the Supervisor's email:

 

Client Script:

ShubhamSingh_0-1699568877029.png

Script Include: (Should be client callable)

ShubhamSingh_1-1699568964850.png

 

CODE:

Client Script:

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

   var ga = new GlideAjax('UserDetailsUtils');
   ga.addParam('sysparm_name', 'getUserEmail');
   ga.addParam('sysparm_user_id', newValue);
   ga.getXMLAnswer(fetchUserEmail);  
}

function fetchUserEmail(answer){
    alert(answer);
}
 
Script Include:
var UserDetailsUtils = Class.create();
UserDetailsUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    getUserEmail : function(){
        var usrID = this.getParameter('sysparm_user_id');
        var usrGr = new GlideRecord('sys_user');
        if(usrGr.get(usrID)){
            return usrGr.manager.email;
        }
        return '';
    },
   
    type: 'UserDetailsUtils'
});
 
Thanks!
 
Mark it as helpful if it works 🙂