Thursday, January 16, 2025

How to get total record count and Top 10 records from D365 Odata GET URL.

How to get total record count, Top 10 records from D365 Odata URL.

Get Total Record count by Odata URL.

1. To retrieve the total record count, we need to use the $count=true keyword in the URL.
{{resource}}/data/VendorGroups?Cross-company=true&$count=true


Get Top 3 records by Odata URL.

1. To retrieve the top 3 records, We need to use $top=3 keyword in the URL.
{{resource}}/data/VendorGroups?Cross-company=true&$top=3

Keep Daxing!!

Wednesday, January 8, 2025

How to Fetch Header and Line Information in a Single D365 OData GET URL

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)


MS ODATA URL


Keep daxing!!