Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

UI formatter showing/hiding on the form based on a choice field and make it mandatory.

shruthi29
Kilo Contributor

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

7 REPLIES 7

Can you please share sample code for this


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){}


}


Community Alums
Not applicable

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.