
Hello everybody, As you probably know, the Xrm.Page command usage is slowly becoming obsolete. That's why we wanted to adapt to the new orders. I created a simple JS to hide a field with the condition that another field is not filled. In the old model, the code works without problems. But as soon as I swap Xrm.Page through ExecutionContext.getFormContext in the code I get a script error while executing. What am I doing wrong ? can someone tell me what my mistake is and how does it work? Here is the old code:
function versteckeFeld(){
if (Xrm.Page.getAttribute("salutation").getValue() == null)
{var name = Xrm.Page.ui.controls.get("new_geschlecht");
name.setVisible(false);}
else
{var name = Xrm.Page.ui.controls.get("new_geschlecht");
name.setVisible(true);}
}
Here is the new code:
function versteckeFeld(){
if (ExecutionContext.getFormContext.getAttribute("salutation").getValue() == null)
{var name = ExecutionContext.getFormContext.ui.controls.get("new_geschlecht");
name.setVisible(false);}
else
{var name = ExecutionContext.getFormContext.ui.controls.get("new_geschlecht");
name.setVisible(true);}
}
Please Help me ^^
I thank you in advance Many greetings :)
*This post is locked for comments
I have the same question (0)Hi ,
Try with this , the only thing you missed that you need to pass executionContext as parameter from onchange event handler.
function versteckeFeld(executionContext){
var formContext = executionContext.getFormContext();
if (formContext.getAttribute("salutation").getValue() == null)
{
var name = formContext.ui.controls.get("new_geschlecht");
name.setVisible(false);
}
else
{
var name = formContext.ui.controls.get("new_geschlecht");
name.setVisible(true);
}
}
See how to pass execution context.
practical-crm.blogspot.com/.../passing-execution-context-to-onchange.html