- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2016 12:17 PM
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.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2016 01:36 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2016 12:28 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2016 01:31 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-02-2017 12:10 PM
How do you assign a field value to an annotation?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-03-2017 08:54 AM
Hi Jack,
The wiki links below should help with setting the field value of annotation
Annotating Forms - ServiceNow Wiki