web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Javascript v9. Xrm.Page and ExecutionContext

(0) ShareShare
ReportReport
Posted on by 95
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)
  • Verified answer
    gdas Profile Picture
    50,091 Moderator on at

    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

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans