简体   繁体   中英

Typescript Dynamics CRM window.parent

Since I am using webresource in my CRM functionality I need to use

window.parent.Xrm.Page...etc 

to access entity data.

Unfortunately, as I write in typescript, this construction won't compile. For now I just add window.parent before Xrm.Page ...(I got Xrm typings) by hand but this is very far from TypeScript idea. Is there any way, some typings or so, that would let me call window.parent.Xrm in a normal, elegant way? I am using Visual Studio

I guess there is no way how to get around grabbing root reference via window.Xrm object, however you can encapsulate it so it happen just once.

If you're using correct ts templates - ie:

Install-Package xrm.TypeScript.DefinitelyTyped

It should be simple as

class Bar {
    constructor(private xrm: Xrm.XrmStatic) {}
    foo() {
        //work in strongly typed world
        //return this.xrm.Page....;
    }
}

And than just once initialize it like

var bar = new Bar(window.Xrm);  
bar.foo();

I use (<any>window.parent).Xrm. in to get an error free compile with window.parent.Xrm . For example:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM