delegateas/XrmDefinitelyTyped

Does the library allow to create the following queries?

dkanaev opened this issue · 1 comments

I have the folowing code:

const bookableResourceBookingList = await XrmQuery.retrieveMultiple(x => x.bookableresourcebookings)    
                .expand(x => x.BookingStatus, x => [x.status])                    
                .select(x => [x.bookableresourcebookingid])                
                .filter(x => 
                          Filter.equals(x.resource_guid, Filter.makeGuid(request.bookableResourceId)))
                .promise();
return bookableResourceBookingList.length;

This code return count of entities by some filter.

  1. I would like to filter data by field of related entity (x.BookingStatus.Status == bookingstatus_status.Canceled) and get count of rows from odata by one request just like this https://stackoverflow.com/questions/30123094/how-to-get-only-odata-count-without-value.
  2. If XrmQuery does not support such queries (count), then I would like to return all records and count them in the client code. In this case I also need to filter the data (x.BookingStatus.Status == bookingstatus_status.Canceled).
  3. If XrmQuery does not support such queries (filter by field of related property), then I would like to return all records, filter by x.BookingStatus.Status and count them in the client code. I see nested BookingStatus property in runtime but autogenerated type does not contain related field and my code does not compile. Please give me an example of code that reads expanded fields.

I have the folowing code:

const bookableResourceBookingList = await XrmQuery.retrieveMultiple(x => x.bookableresourcebookings)    
                .expand(x => x.BookingStatus, x => [x.status])                    
                .select(x => [x.bookableresourcebookingid])                
                .filter(x => 
                          Filter.equals(x.resource_guid, Filter.makeGuid(request.bookableResourceId)))
                .promise();
return bookableResourceBookingList.length;

This code return count of entities by some filter.

  1. I would like to filter data by field of related entity (x.BookingStatus.Status == bookingstatus_status.Canceled) and get count of rows from odata by one request just like this https://stackoverflow.com/questions/30123094/how-to-get-only-odata-count-without-value.
  2. If XrmQuery does not support such queries (count), then I would like to return all records and count them in the client code. In this case I also need to filter the data (x.BookingStatus.Status == bookingstatus_status.Canceled).
  3. If XrmQuery does not support such queries (filter by field of related property), then I would like to return all records, filter by x.BookingStatus.Status and count them in the client code. I see nested BookingStatus property in runtime but autogenerated type does not contain related field and my code does not compile. Please give me an example of code that reads expanded fields.

I had a very similar problem. I think that there is some kind of bug in the XrmQuery typos (check my issue #157). Generally when you use retrieve not retrieve multiple then in expand function you have third parametr which is exactly what you want - filter lambda function. I do not know why there is no such parametr for retrieve multiple. For a workaround I changed my odata query to fetch XML and execute using XrmQuery.