Good evening everyone,
Alright. I'm facing a Xrm.WebApi challenge regarding retrieveRecord. I'm in an entity describing a report. This report entity is related to a main location, say a house. This house is divided in floors. The floors are divided in rooms. The report covers one or more rooms.
Now, a form allows users to select one or more rooms to report on. This is done by means of a subgrid. This subgrid has a QuickView/LookUp view connected to it. This LookUp can be filtered. I had a success with the method described here for filtering on floor, so that users can select rooms for the floor the report is linked to;
https://blog.magnetismsolutions.com/blog/paulnieuwelaar/2018/05/17/filter-n-n-add-existing-lookup-dynamics-365-v9-supported-code
Floor has a direct link to report, so it can be grabbed using the WebApi. With that, a simple filter can be returned. On Success of the WebApi call that is.
However, users must be able to report on rooms on different floors. So, now I need to do an API call that:
- retrieves the current floor from the report
- retrieves the house from the current floor
- with that house retrieve all floors
- and than create a filter that retrieves all rooms on all floors in that house
Can this be done using the "$expand=" option? It seems impossible to retrieve entities one by one. The promises resolve in their own time, I wouldn't know how to handle first grabbing the current floor from the report, than the house, than the floors in that house and lastly the floors, create a filter, set that filter and lastly make the Quick View pop up.
The filter I want to generate can be done in XrmToolBox, and that filter works. It can be set using the method described in the linked article. It looks as follows:
<fetch>
<entity name="room">
<filter>
<condition attribute="floor" operator="in">
<value>b48137a9-b80c-ec11-b6e6-000d3a5bddf1</value>
<value>097c09e9-6be9-eb11-bacb-000d3a5aa426</value>
... more values
</condition>
</filter>
</entity>
</fetch>
So, hard-coding this filter works, but the challenge is to dynamically generate it. How would I go about creating such a WebApi $select$expand statement?
Enjoy the weekend,
- Alex.