Search code examples
dynamics-crm

Querying Dynamics 365 for all salesorderdetails associated with a particular salesorder


I'm trying to get all salesorderdetails associated with a particular salesorder by sending a GET request to the following path:

$"{orgname}/api/data/v9.1/salesorderdetails?$select=salesorderdetailid&$filter=contains(salesorderid,'{salesOrderId}')";

where salesOrderId is a sales order GUID as a string in Dynamics 365. I get the error No function signature for the function with name 'contains' matches the specified arguments. The function signatures considered are: contains(Edm.String Nullable=true, Edm.String Nullable=true).

Is this just not the way to go about getting those associated salesorderdetails?


Solution

  • The correct syntax in your case would be:

    $"{orgname}/api/data/v9.1/salesorderdetails?$select=salesorderdetailid&$filter=_salesorderid_value eq {salesOrderId}";

    because salesorderid is a lookup.

    You can also use my tool Dataverse REST Builder to assist you with the syntax.