How to hide a UI macro button on a form

jeff12345
Kilo Contributor

Hi all,

I wrote a UI macro that creates a button so that users can click it to upload documents to a form instead of clicking the paperclip at the top of the form. Then, I created a formatter using that UI macro so I could use it on my form. I want the button to be hidden when the user loads the form, only appearing after the user selects a choice from a dropdown list on the form. I tried writing a client script, but the button doesn't respond to "g_form.setDisplay(". Any help in solving my problem would be greatly appreciated. Thanks!

1 ACCEPTED SOLUTION

bernyalvarado
Mega Sage

You can use the show_related_records out of the box UI macro as an example of how to manage the visibility of a UI macro within the macro code itself.



https://yourinstanceurl/nav_to.do?uri=sys_ui_macro.do?sys_id=2d8f82a2eb2031001c13abf11206fe83



Thanks,


Berny


View solution in original post

6 REPLIES 6

rob_pastore
ServiceNow Employee
ServiceNow Employee

At of curiosity, are you able to hide it with a UI policy?


If so you can write a custom condition using:


if(g_form.isNewRecord())


to determine if it's a new record or not.




If that doesn't work - you will be forced to use DOM manipulation (which will get flagged in an ACE report). The drawback as this has the potential to break during upgrades. (although it's not very likely to happen)






bernyalvarado
Mega Sage

Hi Jeff, the visibility of the UI macro is often managed within the code of the UI macro itself.



Thanks,


Berny


bernyalvarado
Mega Sage

You can use the show_related_records out of the box UI macro as an example of how to manage the visibility of a UI macro within the macro code itself.



https://yourinstanceurl/nav_to.do?uri=sys_ui_macro.do?sys_id=2d8f82a2eb2031001c13abf11206fe83



Thanks,


Berny


I hope you find this helpful!