Hello,
I am having an issue showing/hiding a field based on the selection. I have a field name "decd_architectural" with just a Yes/No option. If yes is selected, i wanted the "decd_architecturaldatereviewed" to show, else it should be hidden.
I wrote this simple JS below but its not quite working the way I want it. If i toggle "yes", then the field appears but if i switch it back to "No", then it still remains.
function showHideFields(executionContext) {
if(Xrm.Page.getAttribute("decd_architectural").getValue() == "No") {
Xrm.Page.getControl("decd_architecturaldatereviewed").setVisible(false);
}
else {
Xrm.Page.getControl("decd_architecturaldatereviewed").setVisible(true);
}
}
You are missing a condition, and it is not recommended to use xrm.page
I share a code with you
function showHideFields(executionContext) {
// Obtén una referencia al formulario y al campo
var formContext = executionContext.getFormContext(); // Pasa executionContext como parámetro en tu función
var field = formContext.getAttribute("decd_architectural").getValue();
if(field === "false") {
// Para ocultar el campo
formContext.getControl("decd_architecturaldatereviewed").setVisible(false);}
// Para mostrar el campo
if (field === "true"){
formContext.getControl("decd_architecturaldatereviewed").setVisible(true);;
}
}
It is still much easier to do it with a business rule for such a simple functionality.
WarrenBelz
791
Most Valuable Professional
MS.Ragavendar
410
Super User 2025 Season 2
mmbr1606
275
Super User 2025 Season 2