How to Create and Show/Hide Annotations in a Form

ArTex
Tera Contributor

𝐇𝐨𝐰 𝐭𝐨 𝐂𝐫𝐞𝐚𝐭𝐞 𝐚𝐧𝐝 𝐒𝐡𝐨𝐰/𝐇𝐢𝐝𝐞 𝐀𝐧𝐧𝐨𝐭𝐚𝐭𝐢𝐨𝐧𝐬 𝐢𝐧 𝐚 𝐅𝐨𝐫𝐦
Annotations are essential in ServiceNow forms as they enhance user experience, reduce errors, and provide additional support, making processes more intuitive and efficient.

How to create an Annotation

Open the 'Personalize Form Layout' page in the form > Locate the field type '*Annotation' > Select it for the form view.

ArTex_0-1744267029955.png

Annotation Details:

Form Annotation Type –> table 'sys_ui_annotation_type' – where you can define the <style> for your HTML annotation text:

ArTex_2-1744267059092.png

 

To add the content to the text, we will create a Message in the 'sys_ui_message' table in HTML format:

ArTex_4-1744267059094.png

 

After selecting the Style and creating the Message, we can now create the Annotation:

ArTex_6-1744267059096.png

 

View the Annotation in the Form:

ArTex_7-1744267059096.png

 

How to show/hide an annotation through a Client Script

I added a new variable for the demonstration. If the 'Select to hide' checkbox is selected, I want the annotation to be hidden.

ArTex_8-1744267059097.png

 

To do this, we need to reconfigure the annotation:

Open the 'Personalize Form Layout' page in the form > Locate the previously created annotation.

Add an id attribute as a unique identifier for the text so we can reference it in the client script:

ArTex_10-1744267059101.png

New Client Script:

Note: The 'Isolate script' field must be set to false, i.e., not selected.

ArTex_18-1744267375537.png

 

View of the result in the form:

ArTex_20-1744267411363.pngArTex_19-1744267411363.png

4 REPLIES 4

tushar_ghadage
Tera Contributor

Hi @ArTex ,

Does annotation record get captured in update set ???

and if not then do we have move across instances with xml record ??

 

Hi @tushar_ghadage ,

Plese check the response below.

1. Justification (Why they aren't captured)
In ServiceNow, a table's data is only captured in an update set if it has the update_synch=true attribute or extends the sys_metadata table. 
  • sys_ui_annotation is considered a data/content table, not a configuration table like Business Rules or Client Scripts.
  • When you create an annotation via Configure > Form Layout, the layout change is captured (the fact that "an annotation" should be there), but the actual content of the annotation record itself is often left behind. 
 
2. The Solution: Moving Annotations
Since they are not captured automatically, you have three primary ways to move them.
 
Option A: Export/Import XML (Recommended)
This is the most reliable manual method to ensure sys_ids remain identical across instances. 
  1. On the Source Instance, navigate to the Annotations [sys_ui_annotation] list.
  2. Filter for your specific records.
  3. Right-click any column header and select Export > XML (This Record) or XML (All).
  4. On the Target Instance, go to any list view (e.g., sys_user_group), right-click a header, and select Import XML. Upload your file.
 
Option B: Force-Capture via Background Script
If you want the records to stay inside your Update Set for a clean deployment, you can use the GlideUpdateManager2 API. 
  1. Make sure your desired Update Set is active.
  2. Navigate to System Definition > Scripts - Background.
  3. Run the following script (replace 'SYS_ID' with your annotation's ID)

    var gr = new GlideRecord('sys_ui_annotation');
    if (gr.get('YOUR_ANNOTATION_SYS_ID')) {
    var um = new GlideUpdateManager2();
    um.saveRecord(gr);
    gs.print('Record captured in Update Set');
    }

    Option C: "Add to Update Set" Utility
    Many ServiceNow developers use the "Add to Update Set" utility (available on the Developer Share). 
    • Once installed, a related link appears on almost every record in the system.
    • You simply click Add to Update Set on the annotation record, and it will be added to your current active set immediately.
     
    Summary Table
     
    Feature Captured Automatically? Best Movement Method
    Form LayoutYesUpdate Set
    Annotation ContentNoXML Export or Force Script


    Please give it a like if you get the solution helpful for you..




Hi @tushar_ghadage  🙂 

When you change the Form Layout, ServiceNow updates the form configuration and regenerates the annotations. These changes are captured in the update set, and after you retrieve it on another instance, the annotations are created there as well.
ArTex_0-1767602802395.png

 

Please give it a like if you get the solution helpful for you..

Hello @tushar_ghadage , When you change the Form Layout, ServiceNow updates the form configuration and regenerates the annotations. These changes are captured in the update set, and after you retrieve it on another instance, the annotations are created there as well.

Please give it a like if you get the solution helpful for you.