Odata filter query in PowerShell for Dynamics 365

  • Odata filter query in PowerShell for Dynamics 365

    Posted by Raheel Rao on July 18, 2022 at 11:56 am
    • Raheel Rao

      Member

      July 18, 2022 at 11:56 AM

      Writing a script for a pipleline and trying to use a filter on a oData query for D365 F&O data entity however can’t seem to get it to work. I get results without filter however what i’m trying to do is use a EQ operator to filter based on a string value. I’ve tried double quotes, single quotes but none seem to work. Below is the specific line from my PowerShell script

      Get-D365ODataEntityData -EntityName SecurityUserRoleAssociations-Token $token -ODataQuery '$filter=UserID eq "ABC"' 
      


      Please let me know if anyone has any suggestions. Thanks!

      Regards,
      Raheel

      ——————————
      Raheel Rao
      Hickory Farms
      IL
      ——————————

    • Thomas Laza

      Member

      July 19, 2022 at 9:22 AM

      Have you tried using -eq instead of eq ?

      ——————————
      Thomas Laza
      South Texas Electric Cooperative Inc
      Nursery TX
      ——————————
      ——————————————-

    • Raheel Rao

      Member

      July 25, 2022 at 10:48 AM

      Hi Thomas,

      Tried that too and unfortunately that didn’t work either.

      ——————————
      Raheel Rao
      ECCO
      IL
      ——————————
      ——————————————-

    • Thomas Laza

      Member

      July 25, 2022 at 11:53 AM

      Is it possible the filter is case sensitive? If so, you might try all caps on the UserID, or some variation of upper case and lower case.

      ——————————
      Thomas Laza
      South Texas Electric Cooperative Inc
      Nursery TX
      ——————————
      ——————————————-

    • Lenny Kaplan

      Member

      July 26, 2022 at 7:48 AM

      It’s definitely case sensitive. It should be UserId. Also I’m not 100% on this, but you may need to use single quotes to escape single quotes, so your filter would look like this

      '$filter=UserId eq ''ABC'''?

      ——————————
      Lenny Kaplan
      Warburg Pincus LLC
      New York NY
      ——————————
      ——————————————-

    • Ethan Klein

      Member

      March 9, 2023 at 3:25 AM

      To filter data using OData query in PowerShell for Dynamics 365, you can use the Invoke-RestMethod cmdlet with the filter parameter. Here’s an example:

      $resource = “https://<your-instance>.api.<region>.dynamics.com/api/data/v9.0/<entity>?”

      $filter = “startswith(name, ‘A’)”

      $data = Invoke-RestMethod -Method Get -Headers $headers -Uri “$resource`$filter=$filter”

      $data.value

      In this example, replace <your-instance> with the name of your Dynamics 365 instance, <region> with the region where your instance is hosted, <entity> with the name of the entity you want to filter, and startswith(name, ‘A’) with your desired OData filter query.

      You’ll also need to provide the appropriate headers, such as the Authorization header with a valid OAuth 2.0 access token, in order to authenticate with Dynamics 365.

      ——————————
      Ethan Klein
      Digital Marketing Manager
      crecentech
      ——————————
      ——————————————-

    Raheel Rao replied 1 year, 10 months ago 1 Member · 0 Replies
  • 0 Replies

Sorry, there were no replies found.

The discussion ‘Odata filter query in PowerShell for Dynamics 365’ is closed to new replies.

Start of Discussion
0 of 0 replies June 2018
Now

Welcome to our new site!

Here you will find a wealth of information created for people  that are on a mission to redefine business models with cloud techinologies, AI, automation, low code / no code applications, data, security & more to compete in the Acceleration Economy!