How to hide annotation using client script for scoped application

Karishma Dubey
Tera Expert

Hi Team,

I was trying to hide annotation for specific related service. However, it is not working. Please suggest. Related services is a reference field. Isolate script is false and UI type = "All"

 

//onload client scipt

  var rel_services = g_form.getReference('related_service').toString();
    //getValue('related_service');
    alert(rel_services);
     if (rel_services == "67a3e8301b8c62d00b9a11739b4bcba2") {
         info1.style.display = 'block';
     }
     else{
        info1.style.display = 'none';
     }
KarishmaDubey_0-1746191860279.png

 

17 REPLIES 17

@Karishma Dubey 

the client script which is populating that related_services field, there only you add the logic to show/hide annotation

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Ankur Bawiskar 

I added and now it is going inside if but it is not hiding the annotation

function onLoad() {

    //var anno = document.getElementsByClassName("annotation");
    var rel_services = g_form.getValue('related_service').toString();
    alert(rel_services);
   

    if (rel_services == "67a3e8301b8c62d00b9a11739b4bcba2") {
        alert('inside if');
         document.getElementById('info1').style.display = 'block';
        document.getElementById('info1').style.display = 'none';
        //$('info1').up().hide();
       
    } else {
        alert('inside else');

        document.getElementById('info1').style.display = ''; // show
    }






}

@Karishma Dubey 

to hide it should be set as none

Ensure Isolate Script = False for your onLoad client script

try this

function onLoad() {

    var rel_services = g_form.getValue('related_service').toString();
    if (rel_services == "67a3e8301b8c62d00b9a11739b4bcba2") {
        alert('inside if');
        document.getElementById('info1').style.display = 'none';
    } else {
        alert('inside else');
        document.getElementById('info1').style.display = ''; // show
    }
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Ankur Bawiskar I tried with both none and block. it is going inside if but not hiding the annotation

@Karishma Dubey 

Isolate Script = False?

Also can you check by using javascript debugger pressing Ctrl+Shift+Alt+J on form.

Then add your code there and see if it's working by Running the code

AnkurBawiskar_0-1746450679691.png

 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader