delegateas / XrmDefinitelyTyped

Tool to generate TypeScript declaration files for Dynamics 365/CDS client-side coding.
http://delegateas.github.io/Delegate.XrmDefinitelyTyped/
MIT License
133 stars 53 forks source link

Xrm.WebApi.updateRecord function has wrong parameter type #46

Closed lukasbelak closed 6 years ago

lukasbelak commented 6 years ago

There is a definition in xrm.d.ts file under Xrm.WebApiBase interface for updateRecord updateRecord(entityLogicalName: string, id: string, data: string): Then;

When I put data as an object as it is stated here: https://docs.microsoft.com/en-us/dynamics365/customer-engagement/developer/clientapi/reference/xrm-webapi/updaterecord , there is an error during build in VS: Build:Argument of type '{ "name": string; }' is not assignable to parameter of type 'string'.

Your definition expects data as a string, when I put there something like JSON.stringify({"name":"newName"}) and deploy to crm, I get error: An unexpected 'PrimitiveValue' node was found when reading from the JSON reader. A 'StartObject' node was expected.

So this should be changed to: updateRecord(entityLogicalName: string, id: string, data: any): Then; ..because webApi internally call JSON.stringify already.

Could you please change createRecord as well? createRecord(entityLogicalName: string, data: any): Then;

Thanks.

TomMalow commented 6 years ago

Hi Lukasbelak

The way you are trying to update a record is not the intended way of XrmDefinitelyTyped. The definitions you are using is a new feature we have added as part of updating XDT to work with CRM 9.0. Microsoft have a added som new features to make it easier to call the web api. However, XDT contains an interface called XrmQuery that makes it much easier to call the web api and is the intended way of using XDT.

For example:

let contactUpd: Contact = {
    firstname: "Test",
    lastname: "Anderson"
}
XrmQuery.update(x => x.contacts, id, contactUpd)
    .execute(() => {
        Xrm.Page.data.refresh();
    }, error => {
        Xrm.Utility.alertDialog("Action failed: " + error.message)
    });

Going back to the the interface you were using and your suggestion. It is correct that the definition for the updateRecord is incorrect and that data should expect the type string but perhaps instead should expect any. But we are now in doubt whether we should include these definition at all as it is a competing interface for calling the web api and an inferior interface compared to XrmQuery.

lukasbelak commented 6 years ago

Hi Tom, Ok, I understand, the only reason I tried what I described above is that when I wanted to use XrmQuery, I got the error on screenshot.

typerr

Any ideas why property 'displayName' is missing? For example, I generated typings for contact as well and I can use Contact_Update interface without issues, see here:

typerr01

Any ideas, what I am doing wrong here or is there a bug? 'DisplayName' is not even a field on Account entity. L.

magesoe commented 6 years ago

This is an error related to typescript 2.4 and above. Typescript defines an Account interface which automatically gets merged with XDT's generated Account interface. Simply add a namespace to your generated files. This is done through the config for XDT.

lukasbelak commented 6 years ago

@magesoe thanks for an explanation.