how do you show/ hide a formatter on form

beycos
Tera Contributor

Hello everyone, 

I have created a new formatter and this is the UI macro for this Formatter. 

<j:jelly xmlns:j="jelly:core">
  <div id="refreshWrapper" style="margin:5px 0; display:flex; justify-content:flex-end;">
    <button id="refreshBtn"
            class="btn btn-default"
            style="background-color:#007bff; color:white; border-color:#007bff;margin-right:200px;"
            onclick="refre**bleep**emList()">
      Refresh Item List
    </button>
  </div>

  <script>
    function refre**bleep**emList() {
        g_form.save();
       
    }
  </script>
</j:jelly
 
On the form I have choice field called "Type" . 
My aim is this formatter should be hidden when type is null and should be visible when Type is not null.
 
I have created client script
 

function onChange(control, oldValue, newValue) {
setTimeout(function() {
var wrapper = document.getElementById('refreshWrapper');
if (!wrapper) return;

wrapper.style.display = newValue ? 'flex' : 'none';
}, 300);
}

 

However this does not seem to be working. Do you any recommendations or ideas about what might be wrong ? Any help would be appreciated. 

Best Regards, 

Beyza 

 
 
 
 
1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron

@beycos 

the only way is DOM manipulation which is not recommended practice

Ensure for your client script Isolate Script = False

This field is not on form but from list you can make it false

are you using the correct HTML element ID for that -> refreshWrapper

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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

View solution in original post

2 REPLIES 2

Tanushree Maiti
Tera Patron

Hi @beycos 

 

Refer this post: https://www.servicenow.com/community/itom-forum/how-do-you-hide-a-formatter/m-p/985505

 

Try something like it:

 document.getElementById("[the id of the HTML element]").style.display = "none".

Please Accept the solution if it assisted you with your question & Mark this response as Helpful.
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti

Ankur Bawiskar
Tera Patron

@beycos 

the only way is DOM manipulation which is not recommended practice

Ensure for your client script Isolate Script = False

This field is not on form but from list you can make it false

are you using the correct HTML element ID for that -> refreshWrapper

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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