Reference field on Catalog Client Script

Maria DeLaCruz
Tera Guru

Hi,

I need some help with a catalog client script.   I have a u_requested_for field that references the sys_user table.   If the user that's entered in that field has a job title of "Physician", I would like an alert to show.   The job title field name (u_title) on the sys_user table is referencing the u_job_codes table.  

Here's the info on the job title field:

find_real_file.png

Below is my catalog client script that's not working.  

find_real_file.png

I think the issue is on line 6.   I've tried var job = requester.u_job as well, and that doesn't work either.   Please help.

Thanks,

Maria

1 ACCEPTED SOLUTION

Thanks balsu333.   This worked for me.



Here's my updated script:




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


  var user = g_form.getReference('u_requested_for', doAlert);


}


function doAlert(user){


  if(user.u_job == '8d7168dc0f63a900f94f46ace1050ebe'){


  alert('Hospital Staff Physicians requesting Epic or Webmail remote access must contact the Physician Support Line at (866) 405-3742.');


  var URL = "navpage.do";


  top.window.location = URL;


  }


}


View solution in original post

7 REPLIES 7

Chris M3
Tera Guru

I may be incorrect, but I believe a limitation of getReference is that it only returns OOB fields.  


ghsrikanth
Tera Guru

Hi Maria,



You are trying to do double dot-walking and that to in the client script, in this case, its better preferred to do a Glide Ajax call from client script


and return True or false.


Glide Ajax is better way as you will be isolating all the code to check the title of the user away from client script and in server side -


GlideAjax - ServiceNow Wiki



Hopefully it helps


balsu333
Mega Expert

Try with a callback function



find_real_file.png



GlideForm (g form) - ServiceNow Wiki


Thanks balsu333.   This worked for me.



Here's my updated script:




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


  var user = g_form.getReference('u_requested_for', doAlert);


}


function doAlert(user){


  if(user.u_job == '8d7168dc0f63a900f94f46ace1050ebe'){


  alert('Hospital Staff Physicians requesting Epic or Webmail remote access must contact the Physician Support Line at (866) 405-3742.');


  var URL = "navpage.do";


  top.window.location = URL;


  }


}