Restrict visibility of annotation text on a form?

thrsdy1512
Tera Expert

Hi I have added a annotation to a form using form layout. I now want to restrict the visibility of it so that it only displays when a specific option is selected. It's not possible do do this through a UI policy. How can this be achieved?

 

Thanks. 

1 ACCEPTED SOLUTION

@thrsdy1512 

you can use info message to be shown using display business rule using gs.addInfoMessage()

OR

you can use g_form.addInfoMessage() and show it using client script

OR

You can use showFieldMsg() to show messages below your field

I believe I have provided answer to your question and given different approaches and you can enhance it further as per your requirement.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

@thrsdy1512 

not possible via UI policy or client script

you will have to use DOM manipulation for this which is not recommended

this script will help you achieve

Ensure Isolate Script = False to allow DOM

AnkurBawiskar_0-1746021941513.png

 

Give the correct field name, value to compare and the Annotation ID

var val = g_form.getValue('fieldName');
if (val == "value1") {
  document.getElementById('my_annotation').style.display = "none"; // hide it
}
else{

  document.getElementById('my_annotation').style.display = ""; // show
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

I see, would you recommend achieving this a different way instead of using annotations & form layout? I have no problem display a text box at the top of the form using business rule but I am facing issues if I want that same text box to display under a specific form field.

@thrsdy1512 

you can use info message to be shown using display business rule using gs.addInfoMessage()

OR

you can use g_form.addInfoMessage() and show it using client script

OR

You can use showFieldMsg() to show messages below your field

I believe I have provided answer to your question and given different approaches and you can enhance it further as per your requirement.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@thrsdy1512 

Hope you are doing good.

Did my reply answer your question?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader