The CreatorCon Call for Content is officially open! Get started here.

Put a button on a form in an initial hidden state

gmbroth
Kilo Contributor

Hi,

I could use community advice on an implementation issue: I'd like to put a button on a form but have it initially displayed as hidden. Once my form loads (and the button is not visible) I'll then use logic in the onLoad and onChange (for a specific field) scripts to either leave the button hidden or show it.

Unfortunately, the UI Action responsible for displaying the button always renders it as visible (if its Condition evaluates true); if the Condition evaluates false, the button is not added to the form. There is an option to use UI Action Visibility but that suffers from drawbacks: switching views submits the form (my button should be visible before the form is submitted) and you can't switch views on a new form that hasn't been saved yet (my button must be visible on unsaved forms).

My solution is to configure UI Action to show the button and then hide it as necessary using logic in the onLoad script. This does the trick but the button is visible momentarily on the initial page load before the onLoad script can hide it. Is there another approach to putting a button on a form in an initial hidden state?

Thanks, Garry

1 ACCEPTED SOLUTION

Hi Garry,



Yes, I would do one of these.



1. Let the UI Action remain all the time on the form, and do the GlideAjax from the UI Action(on demand), If the CI Exists redirect the user, else alert saying no CI's found. I wont do a GlideAjax unless until necessary especially in this case(REST Message Outbound).


2. Use Field Decoration Macro, That would be visible only when conditions met.



Hope that make sense!!!



Thanks


Srinivas


Mark this answer as helpful/correct if it does so


View solution in original post

9 REPLIES 9

ashik1
Kilo Guru

Try writing a onLoad logic in UI Action condition. I dont see a necessity of onLoad script


Chuck Tomasi
Tera Patron

Hi Garry,



What is the use case here? There may be other solutions to do what you're looking to do than hiding/showing   a UI action if we can understand the underlying requirements. Thanks.


Hi,



Yes, I'd like your thoughts; here's what I'm trying to accomplish: we have a ServiceNow form with a field for the name of a configuration item (CI). We also have a legacy (non-ServiceNow) CMDB application. When the user enters a CI name, we check if it exists in the legacy CMDB (via an Ajax call to the SN backend followed by a RESTMessage call to the legacy CMDB). If the CI does exist in the CMDB, we provide a mechanism (that's the button I've been talking about) for the user to (optionally) launch a new browser tab/window that directs them to a legacy CMDB webpage showing information about the CI. If the CI does not exist in the CMDB, then, obviously, there's no option to visit it.



This must happen when the SN form is still open (i.e., not submitted) because what the user reads on the legacy CMDB webpage may affect the data entries they make on the rest of the SN form before submitting it.



I hope that's a clear explanation. My approach has been to show a button under the right conditions (when the CI exists). What do you suggest?



Thanks, Garry


Although I am not convinced with the approach of using a button for this, but anyway this can help



How to hide/show an UI action on field changes