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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Help with transitioning away from Xrm.Page

(0) ShareShare
ReportReport
Posted on by 2

Good afternoon,

I am testing our Dynamics environment under version 9.0 and I am finding several custom Javascripts are not working due to the use of Xrm.Page

Can someone guide me on how to proceed in converting such functions as the following?

Thank you,

Will

============================

function addTask() {
 Xrm.Utility.openEntityForm('task', null, {
  pId: Xrm.Page.data.entity.getId().replace(/{|}/g, ''),
  pType: Mscrm.EntityPropUtil.EntityTypeName2CodeMap[Xrm.Page.data.entity.getEntityName()],
  pName: Xrm.Page.getAttribute('name').getValue()
 });
}

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Arun Vinoth Profile Picture
    11,615 Moderator on at

    You have to pass the Execution context from Event handler properties window. Then formContext can be extracted from it.

    function addTask(executionContext) {
    var formContext = executionContext.getFormContext(); // get formContext
     Xrm.Utility.openEntityForm('task', null, {
      pId: formContext.data.entity.getId().replace(/{|}/g, ''),
      pType: Mscrm.EntityPropUtil.EntityTypeName2CodeMap[formContext.data.entity.getEntityName()],
      pName: formContext.getAttribute('name').getValue()
     });
    }

    [View:https://docs.microsoft.com/en-us/dynamics365/customer-engagement/developer/clientapi/clientapi-execution-context:750:50]

    [View:https://docs.microsoft.com/en-us/dynamics365/customer-engagement/developer/clientapi/clientapi-form-context:750:50]

    [View:https://docs.microsoft.com/en-us/dynamics365/customer-engagement/developer/clientapi/walkthrough-write-your-first-client-script:750:50]

  • Suggested answer
    Adrian Begovich Profile Picture
    1,027 Moderator on at

    Hi wperkinson3,

    The Dynamics 365 V9 JavaScript Validator plugin in the XrmToolBox can scan your environment for JavaScript web resources to see if they are compatible with the latest version of Dynamics 365. After the scan is complete, the plugin will give you change recommendations for your JavaScript that come in useful when converting your functions.

  • wperkinson3 Profile Picture
    2 on at

    Thank you.

    The above call is being made from a button added by "Ribbon Workbench."  How does one pass the context from Ribbon Workbench?

  • Verified answer
    Arun Vinoth Profile Picture
    11,615 Moderator on at

    You have pass the PrimaryControl as parameter in ribbon command, then consume in function as usual.

    var formContext = primaryControl.getFormContext();


    [View:https://stackoverflow.com/a/48205160/7920473:750:50]

  • wperkinson3 Profile Picture
    2 on at

    Thank you sir.

  • Vikram.kshatri Profile Picture
    35 on at

    Hi Vinoth- how to get the executionContext and formContext in HTML web resource?

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

News and Announcements

Season of Giving Solutions is Here!

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 2

#1
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

#1
Shidin Haridas Profile Picture

Shidin Haridas 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans