Show/Hide Annotations in a "Form Section" on a certain view

veena_kvkk88
Mega Guru

Hi all,

This should be easy but am unable to figure out. I want show/hide annotations based on a choice field. I was able to do this using onChange() client script and by having element id's for each annotation.

function onChange(control, oldValue, newValue, isLoading, isTemplate) {

  if (isLoading) {

  return;

  }

  if(getView() == 'sample_view'){

  if (newValue == "First choice"){

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

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

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

  }

  else if(newValue == "Second choice"){

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

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

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

  }

  else if(newValue == ""){

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

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

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

  }

  }

}

This was working fine when I had these annotations on the main form in the "Sample View". Now I have annotations in a section on the form. When I use the same script, it is unable to locate the elements. Do I have to specify what section these are on? If so, how do I do that? Please help.

1 ACCEPTED SOLUTION

veena_kvkk88
Mega Guru

My bad!! I missed closing the quotes for one of the annotation id's. I thought there was an issue with the script. I feel stupid! Thanks for trying though


View solution in original post

6 REPLIES 6

venkatiyer1
Giga Guru

Hi Veena,



The general pattern for using a field name in document.getElementById would be tablename.fieldname. It should work the same way even on section unless the section is not visible.


But that's the issue. I thought it should too, but it throws an error the way it does when it can't locate the annotations.


How do you assign a field value to an annotation?


Hi Jack,



The wiki links below should help with setting the field value of annotation




Annotating Forms - ServiceNow Wiki



Form annotation