UI formatter showing/hiding on the form based on a choice field and make it mandatory.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-14-2016 09:43 AM
Hi all,
I have a requirement where I have a drop down field, and based on the selection of the choices, I need to make a UI formatter visible/hide on the change request form.(if choice is 'Yes', then show the UI formatter and make it mandatory, if 'No' then hide it.).
Is it possible to achieve this? If yes, kindly share your ideas with me. Any help is high appreciated.
Thanks and Regards,
Shruthi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-20-2017 10:35 AM
Can you please share sample code for this
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-20-2017 12:59 PM
Hi Saidarao,
Try using a top div element in your macro and assign it an ID.
Sample Macro code:
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<div id="hide_macro">
Your HTML code
</div>
</j:jelly>
You can control the visibility of the macro on the form using a client script.
Type: onChange
Sample Script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
try{
if(newValue=="XYZ")
document.getElementById("hide_macro").hide();
else
document.getElementById("hide_macro").show();
}
catch(e){}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-16-2019 02:51 AM
Hi Amlesh,
I tried this code but not worked for me in Madrid version. I have assigned Macro ID as you mentioned but no luck. Could you please help me. For more information, please see my question posted on community -
https://community.servicenow.com/community?id=community_question&sys_id=ad5efff2db7f338c6064eeb5ca96...
Thank you.
