Hiding annotations

Marcel H_
Tera Guru

I am having some issues getting some client scripts to work when trying to hide a custom annotation on a form. I get it working partially, but then after adding either/or onChange or onLoad script, it seems to break even when the correct criteria is met to show the annotation where the annotation appears and then is hidden right away.

What I am trying to do is the following:

  1. Create a custom annotation that I can assign an ID to. In this case I use <span id="tech_note">Technician use only</span>
  2. Once the annotation has an ID, I create a client script for both onLoad and onChange to hide or show the "tech_note" annotation based on the Assignment group value
  3. If the value is "Group X" display the annotation, but any other value to include null/blank it should not be displayed. If the group changes at any time, the conditions in the script should fire as well
  4. I'd like to eliminate the annotation appearing during the loading of the form if at all possible (right now it appears very briefly and then goes away when working)

Any help is appreciated since I've tried a bunch of different examples on this forum and nothing has worked so far. Right now I'm using the following scripts:

onLoad:

function onLoad(){
var group = g_form.getValue('assignment_group');

if (group != 'Group X')
  {
  document.getElementById("tech_note").parentNode.style.display="none";
}

else
  {
  document.getElementById("tech_note").parentNode.style.display="block";
}

}

onChange:

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

if (isLoading || newValue != 'Group X') {

  return;

}

if (newValue == 'Group X')

  {

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

}

else

  {

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

}

}

4 REPLIES 4

Chuck Tomasi
Tera Patron

Hi Marcel,



If you have an onChange and onLoad client script that do the same thing (as in above) you don't need the onLoad client script. Just remove the "isLoading" check and let the onChange script run - it runs automatically onLoad.



FWIW, using document.getElementById (also known as DOM manipulation) is an unsupported practice and can lead to upgrade issues.


Thanks Chuck, I really appreciate the response.



What about the following instead?



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


    var annotation = $('tech_note');


    var group = g_form.getValue('assignment_group');



if (group != "Group X"){


    $("tech_note").up(1).hide();


  }


 


  else {


      if (group == "Group X"){


          $("tech_note").up(1).show();


        }


}


when you do this 'var group = g_form.getValue('assignment_group');' you get sys_id of the group not its name.



so it always goes to below loop


if (group != "Group X"){


    $("tech_note").up(1).hide();


  }



if you want to hide based on the group name, you have to use g_form.getReference.



http://wiki.servicenow.com/index.php?title=GlideForm_(g_form)#getReference


zabeeulla2
Kilo Expert

Hi All,

 

Is there any other way ote than DOM and JQuery to hide annotations via client scripts.

We have been recommended to replace all DOM/JQuery manipulations as they may have upgrade implications 

Any pointers/help is appreciated.

 

Regards,

Zabee