Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Display Field Message under form field depending on Location value

ESanchez013
Tera Expert

I am looking on how to best format a Client Script (I have very little code experience) to display a field message (g.form.showFieldMsg) below the Location field when the Location has a specific value in its record.

For example, in my development instance, the "Dallas" location has a field called "Time zone" and it is US/Central.

Any time a record is being created for a Location whose Time zone value is "US/Central," I'd like to display a message below the Location field in the incident form with something like "This location is in the Central time zone."

find_real_file.png

3 REPLIES 3

Yousaf
Giga Sage

Hi Edward,

You can try onChange client script on location field. Just use correct field names.

var timeZone = g_form.getValue('location.time_zone');
if(timeZone== "US/Central"){

g_form.showFieldMsg('This location is in the central time zone.');
}

 

Mark Correct and Helpful if it helps.


***Mark Correct or Helpful if it helps.***

Thanks!

Do you know how I can set multiple conditions other than just the one 'if'?

Like if the time zone is US/Pacific, then say "This location is in the Pacific time zone" etc.

ESanchez013
Tera Expert

Doesn't seem to work.

Here is what I have coded:

 

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

   //Type appropriate comment here, and begin script below
   var timeZone = g_form.getValue('cmn_location.time_zone');
   if(timeZone== "US/Central"){
   g_form.showFieldMsg('This is in the Central time zone.');
}
}