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 :
Customer experience | Sales, Customer Insights,...
Unanswered

Xrm.Page deprecation and lost form context

(0) ShareShare
ReportReport
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!

I have the same question (0)
  • Shaun W Harvey Profile Picture
    242 on at

    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!

  • Christopher Klein Profile Picture
    20 on at

    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
    242 on at

    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

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 > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 96 Super User 2025 Season 2

#2
Jimmy Passeti Profile Picture

Jimmy Passeti 50 Most Valuable Professional

#3
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 49 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans