g_form.getReference issue in portal

manibaig
Mega Guru

Requesting Access (User/E": TypeError: Unable to get property 'email' of undefined or null reference

here is the code (working fine on platform but not on portal), i am not sure how to use GlideAJAX. Appreciate your help

var userID = g_user.userID;

var isPM = g_user.hasRole('pm');

function onChange(control, oldValue, newValue, isLoading) {

   if (isLoading || newValue == '') {

      return;

   }

if(isPM){

g_form.setValue('u_user_s_email_address', g_form.getReference('u_user_name').email);

g_form.setValue('u_hire_submission_date', g_form.getReference('u_user_name').u_hire_submission);

g_form.setValue('u_user_s_telephone', g_form.getReference('u_user_name').phone);

} }

1 ACCEPTED SOLUTION

DScroggins
Kilo Sage

In order to use g_form.getReference() in portal you must use a callback function like so:


function onChange(control, oldValue, newValue, isLoading) {

   if (isLoading || newValue == '') {

      return;

   }

var userID = g_user.userID;

var isPM = g_user.hasRole('pm');

if(isPM){

g_form.getReference('u_user_name',function(user){

g_form.setValue('u_user_s_email_address', user.email.toString());
g_form.setValue('u_hire_submission_date', user.u_hire_submission.toString());
g_form.setValue('u_user_s_telephone', user.phone.toString());

});

}

}

 

 You can also utilize GlideAjax to call a script include then return the user values as needed.

 

Please see the below link for reference on what client scripts and APIs work in Service Portal:

Service Portal & Client Scripts

View solution in original post

7 REPLIES 7

This would work on both UI right?

Yes this script will work in both the main UI and also Service Portal as long as the client script is marked UI Type = "All".

it only changes the email address and if i comment out the email address , then it changes the next field. Not sure why.