can we hide custom button using onchange client script ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-05-2023 09:59 PM
Hi Team ,
We created a custom button in the form .
My requirement is when user changes the state field ,we are making few fields blank and want to hide/disable the custom button .
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
g_form.setValue('date', "");
g_form.setValue('last_com', "");
we are making few fields blank ,but how to make custom button hide/disable ?
Please guide
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-05-2023 10:03 PM
You would do this in the conditions of the UI Action.
https://www.servicenow.com/community/developer-forum/how-to-set-condition-on-ui-action/m-p/1790215
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-05-2023 10:51 PM
Hello @String
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
Plz Mark my Solution as Accept and Give me thumbs up, if you find it helpful.
Regards,
Samaksh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-05-2023 11:36 PM
Hi @Samaksh Wani thanks for your quick reply ,we using scope application
We are using two buttons on top ,so when state changes one button should show and second button should disable/hide
Please guide me
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-05-2023 11:51 PM
Hello @String
Go to UI policy, add your If Condition with state changes , in it add it
3) In the if condition write
$$('#action_name')[0].hide(); //This will hide the top button
$$('#action_name')[1].show(); //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