Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Unanswered

Xrm.Page deprecation and lost form context

Posted on by 20

Hello,

According to this Article "Important changes (deprecations) coming in Power Apps and Power Automate - Power Platform | Microsoft Learn" Xrm.Page is deprecated and will be removed from future release.

We've gone through our JavaScript code base and removed where it is used but I have a recurring situation where I'm not sure why I am losing form context.

We have this code which is called in almost every script page we have

export function getFormContext(parent?: Window): Xrm.FormContext {
let context: Xrm.FormContext;

if (formContext) {
context = formContext;
} else {
LogHelper.logUiException(new Error().stack, "No form context!!!");
}
return context;
}

It works fine but sometimes it will throw the error for 'No form context' which in of itself doesn't cause a problem but I dont know why it would not have a form context?

Has anyone else came across this and do you have any solutions?

Thanks!

  • Shaun W Harvey Profile Picture
    Shaun W Harvey 240 on at
    RE: Xrm.Page deprecation and lost form context

    Hi Christopher,

    I have to admit I am reaching the limits of my knowledge in this area.

    The below article seems to suggest the scenario when you have a button that can appear on either the main Form Ribbon OR the Grid ribbon.

    You can choose which context you want to pass in. The main Form Context or the Grid Context.

    learn.microsoft.com/.../pass-data-page-parameter-ribbon-actions

    But I don't think that is what you are doing.

    Sorry. Thought I might be onto something there.

    Best Regards.

    Shaun

  • RE: Xrm.Page deprecation and lost form context

    Hi there,

    The functions are being called both from forms and ribbons.  "Pass execution context as first parameter" is selected for all.

    I'm not sure what you mean by "if you are calling from a ribbon or grid you get a different context object"?  Do you mean if I have a ribbon on a form and load the form context and then go to call the ribbon it will instantiate a new context so the call I'm making it hitting the code that has to get the context and log the error is valid?

    thanks

  • Shaun W Harvey Profile Picture
    Shaun W Harvey 240 on at
    RE: Xrm.Page deprecation and lost form context

    Hi,

    Are all of the functions being called from Events on the Forms?

    If so, is "Pass execution context as first parameter" ticked?

    Then you can get the Form Context using:

    function displayName(executionContext)

    {

      var formContext = executionContext.getFormContext(); // get formContext

      // use formContext instead of Xrm.Page  

      var firstName = formContext.getAttribute("firstname").getValue();

      var lastName = formContext.getAttribute("lastname").getValue();

      console.log(firstName + " " + lastName);

    }

    If you are calling from a Ribbon or Grid you get a different context object.

    Apologies if you have already done this.

    Good Luck!

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans