delegateas/XrmDefinitelyTyped

Problem with types when using retrieveMultiple in typescript

lawsl opened this issue · 3 comments

lawsl commented

Describe the bug
When trying to filter solutions based on related accountid and name of the other solutions on the related account.
accounid comes out as a string but the related account requires a guid, and the only way I could make it works was casting accountId as any which is not optimal

Expected behavior
I think that either accountid should be a guid or the filter should expect a string

Screenshots

image
Environment

Have you tried using the Filter.makeGuid function to turn a string into a guid?

lawsl commented

yes, the filter.makeguid made a guid formatted like (guid'{xxxxxxxx-xx-xxxxxx}) which didn't work with filter.equals
the ppm_account_guid and accountid comes out excactly the same but can't be compared because one is a string and one is a guid

As magesoe says Filter.makeGuid should solve this for you. When Dynamics 365 resolves your filters, it ignores braces '{}' around your guids as well as casing.

I made the below test (with a hardcoded guid from a trial environment), and even though the primary contact have to match all four different values, the query still finds an account.

let account = await XrmQuery
    .retrieveMultiple(x => x.accounts)
    .filter(x => Filter.equals(x.primarycontactid_guid,  "2C03653C-39CD-EC11-A7B5-000D3A471234" as any))
    .filter(x => Filter.equals(x.primarycontactid_guid, "{2C03653C-39cd-EC11-A7B5-000D3A471234}" as any))
    .filter(x => Filter.equals(x.primarycontactid_guid,  "2c03653c-39cd-ec11-a7b5-000d3a471234" as any))
    .filter(x => Filter.equals(x.primarycontactid_guid, "{2c03653c-39cd-ec11-a7b5-000d3a471234}" as any))
    .promiseFirst();