Only show annotation on new record forms?

perkinsarm
Mega Guru

We would like to provide some instructions, but only on a new record form. There is a use case to allow some users access to the regular form but in specific cases we want to make sure that appropriate record producers are used. We added an Annotation to the form containing instructions and links to those record producers. The annotation isn't appropriate when a record already exists.

Is there a simple way to remove the Annotation from the form if the record is not new?

I've seen proposed solutions where you try to hide it with CSS hacks but they leave a space where it would normally appear.

Is there a possibly better alternative solution?


Thanks,

Brad

1 ACCEPTED SOLUTION

perkinsarm
Mega Guru

The solution I found was to avoid using an Annotation altogether. Trying to hide it with the View Rules solution would require too much effort. Hiding it by manipulating the DOM was theoretically possible, but I couldn't make a Client Script to do that.   Instead I removed my annotation and simply created an On Load client script that uses g_form.addInfoMessage(same annotation text) to the same effect.


function onLoad() { // Display instructions and links if the form is displaying an existing record. if(g_form.isNewRecord()){ g_form.addInfoMessage([html that mimics the desired annotation]'); } }


View solution in original post

10 REPLIES 10

My view rule form doesn't have an Advanced link? We are still on Fuji if that matters?


Mihir Mohanta
Kilo Sage

Write a on load client script.



  if (g_form.isNewRecord())


  {


    document.getElementById("annot").parentNode.style.display="block";


  }


  else


  {


  document.getElementById("annot").parentNode.style.display="none";


  }




Change the   the id name(Bold text)



Thanks,


Mihir


Warning: DOM access is risky. It may not work across ServiceNow releases.



Client Script Best Practices - ServiceNow Wiki


I agreed w Chuck Tomasi that modifying the DOM isn't a good solution, but tried it anyway. I could not get it to work within the script. I was able to hide the Annotation by fiddling around in the browser console, so DOM manipulation is possible. This was helpful as it led me to find a simple solution that works which I'll post in response to my original question.


perkinsarm
Mega Guru

The solution I found was to avoid using an Annotation altogether. Trying to hide it with the View Rules solution would require too much effort. Hiding it by manipulating the DOM was theoretically possible, but I couldn't make a Client Script to do that.   Instead I removed my annotation and simply created an On Load client script that uses g_form.addInfoMessage(same annotation text) to the same effect.


function onLoad() { // Display instructions and links if the form is displaying an existing record. if(g_form.isNewRecord()){ g_form.addInfoMessage([html that mimics the desired annotation]'); } }