openlang

Dynamics CRM access from TypeScript

Because my CRM code runs in a webresource, I have to write

window.parent.Xrm.Page...etc

to retrieve the entity's data.

Regrettably, that expression fails to compile when I'm writing typescript. Currently I insert window.parent ahead of Xrm.Page...(the Xrm typings are installed) manually, which rather defeats the point of TypeScript. Could typings, or another approach, allow me to access window.parent.Xrm cleanly in the usual way? My editor is Visual Studio

The conversation continues 2

Follow the reasoning
  1. Permalink

    I don't think you can avoid obtaining the root through the window.Xrm object, but wrapping that access means doing it only once.

    With the appropriate ts templates installed - namely:

    Install-Package xrm.TypeScript.DefinitelyTyped

    Something this straightforward should work

    class CrmAccess {
      constructor(private context: Xrm.XrmStatic) { }
      read() {
        //stay within the typed environment
        //return this.context.Page....;
      }
    }

    Then initalise it just once as follows

    var crmAccess = new CrmAccess(window.Xrm);
    crmAccess.read();
  2. Permalink

    In typescript (/questions/tagged/typescript), I write (<any>window.parent).Xrm. so that using window.parent.Xrm compiles without an error. Here's an example:

    let titleValue = (<any>window.parent).Xrm.Page.data.entity.attributes
      .get("name").getValue()

Other sides of the same question

  1. Making the sender appear as a label instead of an email address using Java Mail

    Im sending messages through the Java Mail API. On arrival, the inbox displays the address that sent the message. Id like some…

    Replies 2Latest activity java
  2. What date formatting does a Gleam HTTP response header need?

    I want to send a Date header. The required format looks like this: This is my current attempt:

    Replies 3Latest activity gleam
  3. Fastest approach for filling a Mat region with zero using OpenCV C++?

    What would be the most efficient approach for filling one area within a grayscale Mat image with zeros (or, indeed, with anot…

    Replies 3Latest activity cpp