Display help text conditionally in service portal

Annika Aaltonen
Kilo Guru

Hi,

I need to expand (alternatively display) the help text on variable A, when variable A has value X, and preferably also revert back when not true. I found this article:

https://community.servicenow.com/community?id=community_question&sys_id=7a24c329dbd8dbc01dcaf3231f9619c3&view_source=searchResult

but I can't seem to get it to work. Do I need to change some bit, since I need it for Service Portal UI? 

Or has something changed since, it's a 2 yr old post?

 

Here is what I got from this post, please tell me what is wrong here:

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


     //Type appropriate comment here, and begin script below

var val =g_form.getValue('A');
if(val == 'X'){
 
var elems = document.getElementsByClassName('sc-help-text annotation-wrapper');
   for (var i=0;i<elems.length;i+=1){
 
   if (elems[i].style.display === 'none') {
   elems[i].style.display = 'block';
   }
 
   }
}
}

Or maybe nothing is wrong with my script, but something else I'm completely missing..

Thanks in advance!

Annika

 

1 ACCEPTED SOLUTION

I tried below script in my PDI and it works for me.

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }
if (newValue=='admin'){
	alert('test');
   g_form.showFieldMsg('type_of_request','This is a test','info',true);
}
	 else{
 g_form.hideFieldMsg('type_of_request');
 }
}

find_real_file.png

View solution in original post

7 REPLIES 7

Hi Vignesh,

Thanks, this indeed seems very promising!

However, I tested this field message a bit (with my very limited javascript knowledge), but couldn't get it to work. I'm not 100% convinced this works for SP UI, at least the article doesn't mention SP. Then again alert works, so...

Can you please show me how to script would look like in onChange Cat. Client Script, when used in the scenario where "Variable A has value X". Appreciate your help, I''m still very new to all of this 🙂

 

Best,

Annika

I tried below script in my PDI and it works for me.

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }
if (newValue=='admin'){
	alert('test');
   g_form.showFieldMsg('type_of_request','This is a test','info',true);
}
	 else{
 g_form.hideFieldMsg('type_of_request');
 }
}

find_real_file.png

Perfect, now it worked, thanks a lot!!

 

/Annika