Skip to content

Commit f284dab

Browse files
authored
Dynamic Visible UI Actions (ServiceNowDevProgram#878)
* Create README.md * Update README.md * Create script.js
1 parent 4c17544 commit f284dab

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Dynamic Visible UI Actions
2+
3+
This code snippet can be used to dynamically change the visibility of an UI action via a Client Script or UI Policy.
4+
As this happens on the client, it happens without the need of saving/reloading the form like you'd have to do if controlled via the UI Action's condition field (server-side).
5+
6+
As this uses DOM manipulation you might have to uncheck the "Isolate Script" field on the Client Script or UI Policy to make it work or make sure you have a system property "glide.script.block.client.globals" with a value of false if you're in a scoped application.
7+
8+
**Note**: DOM manipulation should be used with caution.
9+
10+
11+
12+
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
2+
if (isLoading || newValue === '') {
3+
return;
4+
}
5+
6+
// Adjust condition to your needs
7+
if (newValue === "true") {
8+
$$('button[data-action-name^=action_name').each(function(e) { // replace action_name with the action name of the UI Action
9+
e.hide();
10+
});
11+
} else {
12+
$$('button[data-action-name^=action_name').each(function(e) { // replace action_name with the action name of the UI Action
13+
e.show();
14+
});
15+
}
16+
}

0 commit comments

Comments
 (0)