How to Fetch 2 entities Information in a Single D365 OData GET URL
1. When using the GET operation, it retrieves all information from the specified entity by default.
2. In some cases, we need information from two related tables, such as header and line data. For this we need to trigger D365 twice with different URL.
3. To achieve this, a relationship must exist between these two entities.
4. In the example below, I fetched data from PurchaseOrderHeadersV2 and PurchaseOrderLinesV2.
The below purchase order has 2 lines:
5. I used the $expand keyword to include data from the related table and $select to specify the fields to retrieve.
{{resource}}/data/PurchaseOrderHeadersV2?$filter=dataAreaId eq 'USMF' and PurchaseOrderNumber eq 'PO-000218'
&Cross-company=true&$select=dataAreaId,PurchaseOrderNumber,OrderVendorAccountNumber,PurchaseOrderName,PurchaseOrderStatus
&$expand=PurchaseOrderLinesV2 ($select=dataAreaId,PurchaseOrderNumber,LineNumber,OrderedPurchaseQuantity,ItemNumber,PurchasePrice)
6. Below is an example URL without using the $select keyword:
{{resource}}/data/PurchaseOrderHeadersV2?$filter=dataAreaId eq 'USMF' and PurchaseOrderNumber eq 'PO-000218'
&Cross-company=true&$select=dataAreaId,PurchaseOrderNumber,OrderVendorAccountNumber,PurchaseOrderName,PurchaseOrderStatus
&$expand=PurchaseOrderLinesV2
Without Purchase order filter.
{{resource}}/data/PurchaseOrderHeadersV2?$filter=dataAreaId eq 'USMF' &Cross-company=true
&$select=dataAreaId,PurchaseOrderNumber,OrderVendorAccountNumber,PurchaseOrderName,PurchaseOrderStatus
&$expand=PurchaseOrderLinesV2 ($select=dataAreaId,PurchaseOrderNumber,LineNumber,OrderedPurchaseQuantity,ItemNumber,PurchasePrice)
Keep daxing!!
No comments:
Post a Comment