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 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

VigneshMC
Mega Sage

DOM manipulation is not supported in service portal. Please refer below link

https://docs.servicenow.com/bundle/madrid-servicenow-platform/page/build/service-portal/concept/unsu...

 

Thanks

nayanawadhiya1
Kilo Sage

find_real_file.png

Annika Aaltonen
Kilo Guru

Thanks! That explains it completely 🙂 Is there any smoother way to do this, than to display some sort of label variable with Cat. UI policy then?

 

Cheers,

Annika