Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

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

Ankur Bawiskar
Tera Patron
Tera Patron

@Karishma Dubey 

this should work fine -> you should get the HTML ID

function onLoad() {

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

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

Hi @Ankur Bawiskar ,

I am not getting alert only.it is coming empty and not working

@Karishma Dubey 

I hope field related_service is on form and is reference type

the logic I shared should work fine provided the field is present on form, sysId you are comparing is correct and Isolate script is false 

function onLoad() {

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

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 this hide annotation script is getting called before the related_services populates on form.  hence it is going to else block. I changed the script order but the issue is still the same. Any suggestions here?