- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2022 10:11 PM
Hi All,
We have a requirement to hide "request approval" button on change request form, based on the selection of field "Type" If the type is comprehensive then we need to hide RequestApproval button.
UI action is working only for onload. So I tried using DOM manipulator in client script. but it is trowing some error's. Please let me know, how to achieve this.
Script:
document.getElementById("requestapproval").style.display = 'none';
Error:
Thanks,
Supriya.
Solved! Go to Solution.
- Labels:
-
Change Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2022 08:57 AM
Hi,
try this in the onChange client script of Type field
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
if (newValue == 'comprehensive') {
var items = $$('BUTTON').each(function(item) {
if (item.innerHTML.indexOf('Request Approval') > -1) {
item.show();
}
});
}
else {
var itemss = $$('BUTTON').each(function(item) {
if (item.innerHTML.indexOf('Request Approval') > -1) {
item.hide();
}
});
}
//Type appropriate comment here, and begin script below
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2022 10:21 PM
Hi supriya,
1) Create a UI Policy --> Set Condition as field (check_box) is true
2) In the Script tab set Run scripts true
3) In the if condition write
$$('#action_name')[0].hide(); //This will hide the top button
$$('#action_name')[1].hide(); //This will hide the bottom button as well
4) In the else condition write
$$('#action_name')[0].show(); //This will show the top button
$$('#action_name')[1].show(); //This will show the bottom button as well
For reference,
check this How to hide/show an UI action on field changes
Please mark helpful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2022 10:37 PM
Hi Mayur,
I have tried the UI policy and still facing the error. In the step 1 : what do you mean by check_box?
"Set Condition as field (check_box) is true". Please check my script below.
Error:
onChange script error: TypeError: Cannot read properties of undefined (reading 'hide') function () { [native code] }
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2022 10:21 PM
Hi,
Usually UI actions are shown/hidden based on UI action condition and it gets evaluated only once.
Using DOM manipulation is not recommended.
I hope you must have marked Isolate Script Field = False for the UI action to allow DOM manipulation
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2022 10:39 PM
Hi Ankur,
Do I need to allow isolate script for UI action button "Request approval"? Can we achieve this without using DOM?
Thanks,
Supriya.