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

Notifications

Announcements

No record found.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans