How to show a field message based on User criteria

DevtoSME
Giga Guru

On thee Incident form I want to display a message under the "Caller" field that says the user is Elite if the grades of service field on the user tables shows the elite option. (picture attached) 

 

I'm working on a client script and need help with how to structure the code. new to coding

any help would be appreciated. 

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }
 
   var userGradesOfService = g_form.getValue('caller_id.u_grade_of_service');
   if (userGradesOfService === "elite") {
      g_form.showFieldMsg('This user is Elite');
   }
}
1 ACCEPTED SOLUTION

Isaac Swoboda
Tera Expert

Hello Joyea, 

 

The reason it is not working in your current implementation is because on the Client side you cannot "dot-walk" into the GlideRecord it is referencing. You would need to call the Server to get the relevant data. 

 

There are a few ways to handle this.

 

  1. You could use GlideAjax which would require you to also write a corresponding Script include to return the data you needed.
  2. Use the GlideForm getReference method followed by a callback function to process the results. 

Taking your example, I would rewrite it as such:

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

   g_form.getReference('caller_id', function (userGR) {
      var userGradesOfService = userGR.u_grade_of_service;
      if (userGradesOfService == "elite") {
         g_form.showFieldMsg('caller_id', 'This user is Elite', 'info');
      }
   });
}

View solution in original post

2 REPLIES 2

Isaac Swoboda
Tera Expert

Hello Joyea, 

 

The reason it is not working in your current implementation is because on the Client side you cannot "dot-walk" into the GlideRecord it is referencing. You would need to call the Server to get the relevant data. 

 

There are a few ways to handle this.

 

  1. You could use GlideAjax which would require you to also write a corresponding Script include to return the data you needed.
  2. Use the GlideForm getReference method followed by a callback function to process the results. 

Taking your example, I would rewrite it as such:

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

   g_form.getReference('caller_id', function (userGR) {
      var userGradesOfService = userGR.u_grade_of_service;
      if (userGradesOfService == "elite") {
         g_form.showFieldMsg('caller_id', 'This user is Elite', 'info');
      }
   });
}

DevtoSME
Giga Guru

I was ablet to crate a script include and this worked perfectly!