The Now Platform® Washington DC release is live. Watch now!

Help
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

g_form.getReference issue in portal

manibaig
Kilo 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
Tera Guru

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

sachin_namjoshi
Kilo Patron
Kilo Patron

g_form.getReference() DOES NOT work in service portal.

You will have to use glide Ajax.

 

 

 

Regards,

Sachin

can you share glide Ajax code (i am new to glide Ajax)

Please find below code for glide ajax for your requirement

https://community.servicenow.com/community?id=community_article&sys_id=9f7ce2e1dbd0dbc01dcaf3231f96196e

 

Regards,

Sachin

 

DScroggins
Tera Guru

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