Hide Annotation with Client Script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2009 12:46 PM
Is it possible to hide an Annotation with a client script the way we can make fields visible/invisible?
I'd like to be able to hide an Annotation along with a set of fields for a specific set of users.
As a workaround, I suppose I could create an actual field with a colored label, but that seems like brute force.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-12-2016 06:27 AM
Hi,
Rather than using an annotation could you instead use "g_form.addInfoMessage" in an onLoad client script.
This would display at the top of the screen.
Something similar to the below would work:
Name: Example Show message
Type: OnLoad
Script: (use either an "if" or a "switch" depending on your conditions)
- var condition = g_form.getValue('field_name');
- if(condition) {
- g_form.addInfoMessage("Info text to go here");
- }
switch (condition) { case 'value': g_form.addInfoMessage("Switch case one text"); break; case 'value_2': g_form.addInfoMessage("Switch case 2 text"); break;
If you need to place this info message under a specific field, try one of the following which can be found on the wiki at : Scripting Alert, Info, and Error Messages - ServiceNow Wiki
2 Business rule and other general use
- current.field_name.setError("Hello World"); Will put "Hello World" below the specified field
- gs.addInfoMessage("Hello World"); Will put "Hello World" on the top of the screen
- gs.print("Hello World"); Will write to the text log on the file system but not to the sys_log table in the database
- gs.log("Hello World"); Will write to the database and the log file. Too much of this can adversely affect performance
3 Client side (NOTE: only for use with client scripting)
- alert("Hello World"); Will pop up a window with "Hello World" and an 'OK' button.
- confirm("Hello World"); Will pop up a window with "Hello World?" and a 'Ok' and 'Cancel' buttons.
- g_form.showErrorBox("field_name", "Hello World"); Will put "Hello World" in an error message below the specified field.
- g_form.hideErrorBox("field_name"); Will hide an error box that is visible under the specified field.
It's also possible to add other custom messages to your forms if necessary using client scripting.
Hope this helps,
Victor.
