Please wait, loading...

 

Filter Query , Expand Query in Power Automate flow – Get Collection of record from CDS Microsoft dynamics 365 – List Records using Odata filter query Orderby Expand Query

June 14, 2020

There are two options to retrieve record or records from Microsoft dynamics 265 CDS
1. Get a Record
2. List Records

1. Get a Record:

This is quite simple where we want to get Get a single record by passing Primary key of the record which means we have Primary field value that is GUID ( Case has Account lookup )
i.e Get Account Record where account = <GUID>

https://i0.wp.com/microsoftdynamics.in/wp-content/uploads/2020/06/img_5ee51cf98c9bd.png?fit=1502%2C245&ssl=1

2. List Records:

This action returns a collection of record for whichever entity is selected, it would be quite easy to understand if we know how to use ODATA query especially Functional or nontechnical,

Click here check how to create a query using ODATA (Its Quit easy)

So, in short, we can apply Almost all Queries of  OData example

  1. Filter ($filter) in list Records action to fetch filtered record collection
    i.e data/v9.1/accounts?$filter=statecode eq 0
  2. Order By ($orderby) in list Records action to fetch records in Particular Order
    i.e data/v9.1/accounts?$orderby=name desc
  3. Top ($top) Count in list Records action to fetch $top Qualifier
    i.e data/v9.1/accounts?$top=5
  4. Expand ($Expand) in list records action to pull Related Entity and apply $select to specify Attribute of the related entity
    i.e data/v9.1/accounts?$top=5$expand=primarycontactid($select=fullname)

ONE: FILTERSThere are several Operators we can apply on to filtering and divide into below

1. Logical Operators i.e Equal, Not Equal, And, Or, Greater Than, Less Then E.T.C
2. Arithmetic Operators i.e Addition, Subtraction E.T.C
3. Canonical Functions i.e Contains, length, Startswith, date E.T.C
4. Lambda Operators i.e Any, All

Filter Example 1: Get all Account record collections from DEV environment

ODATA : https://dvmske0.crm8.dynamics.com/api/data/v9.1/accounts

https://i0.wp.com/microsoftdynamics.in/wp-content/uploads/2020/06/img_5ee52424eb16d.png?fit=1591%2C570&ssl=1

Power Automate: List records action, select environment, and Entity with no Data filter

https://i0.wp.com/microsoftdynamics.in/wp-content/uploads/2020/06/img_5ee522b1080a6.png?fit=1649%2C388&ssl=1

Filter Example 2: Get all Active account ( Status equals active)

ODATA : https://dvmske0.crm8.dynamics.com/api/data/v9.1/accounts?&$filter=statecode eq 0

https://i0.wp.com/microsoftdynamics.in/wp-content/uploads/2020/06/img_5ee52972896ec.png?fit=1710%2C361&ssl=1

Power Automate: List records action, select environment, and Entity with  ODATA Filter as “statecode eq 0

https://i0.wp.com/microsoftdynamics.in/wp-content/uploads/2020/06/img_5ee522b1080a6.png?fit=1649%2C388&ssl=1

Filter Example 3: Get All Account (Created on Date is GreaterThan '2020-06-09')

ODATA : https://dvmske0.crm8.dynamics.com/api/data/v9.1/accounts?$filter=createdon gt ‘2020-06-09’

https://i0.wp.com/microsoftdynamics.in/wp-content/uploads/2020/06/img_5ee5360e4f034.png?fit=1564%2C330&ssl=1

Power Automate: List records action, select environment, and Entity with  ODATA Filter as “createdon gt ‘2020-06-09

https://i0.wp.com/microsoftdynamics.in/wp-content/uploads/2020/06/img_5ee5368f977b1.png?fit=1502%2C398&ssl=1

Filter Example 4: Get All Account (Lead Title Contains Refund OR Lead Title Not Contains Credit)

ODATA : https://dvmske0.crm8.dynamics.com/api/data/v9.1/leads?$filter=contain(subject,’refund’) or not contaains(subject,’credit’)

https://i0.wp.com/microsoftdynamics.in/wp-content/uploads/2020/06/img_5ee543f37eae2.png?fit=1532%2C672&ssl=1

Power Automate: List records action, select environment, and Entity with  ODATA Filter as “contain(subject,’refund’) or not contaains(subject,’credit’)

https://i0.wp.com/microsoftdynamics.in/wp-content/uploads/2020/06/img_5ee5444bb8824.png?fit=1621%2C379&ssl=1

Below are all possible Examples and Operations used in Odata Filtering taken from https://docs.oasis-open.org/ , Link is provided within the examples and at the end of post

Logical Operators

OData defines a set of logical operators that evaluate to true or false based on which filters are applied

Equals
Not Equals
Greater Than
Greater Than or Equal
Less Than
Less Than or Equal
And
Or
Not
has

Example: all products with a Name equal to ‘Milk’

$filter=Name eq 'Milk'

Example: all products with a Name not equal to ‘Milk’

$filter=Name ne 'Milk'

Example: all products with a Name greater than ‘Milk’:

$filter=Name gt 'Milk'

Example: all products with a price greater than or equal to 100:

$filter=Price ge 100

Example: all products with a price  less than 100:

$filter=price lt 100

Example: all products with a Price less than or equal to 100:

$filter=Price le 100

Example: all products with the Name ‘Milk’ that also have a Price less than 2.55:

$filter=Name eq 'Milk' and Price lt 2.55

Example: all products that either have the Name ‘Milk’ or have a Price less than 2.55:

$filter=Name eq 'Milk' or Price lt 2.55

Example: all products that do not have a Name that ends with ‘ilk’:

$filter=not endswith(Name,'ilk')

Example: all products whose style value includes Yellow:

$filter=style has Sales.Pattern'Yellow'

Canonical Functions

If a parameter of a canonical function is null, the function returns null.

contains
endswith
startswith
length
indexof
substring
tolower
toupper
trim
concat
year
month
day
hour

Example: all Account with a Name contains ‘DVMSKE’

$filter=contains(name,'dvmske')

Example: all account with a name endswith ‘pvt ltd’

$filter=endswith(Name,'pvt ltd')

Example: all Account with a Name startswith ‘Dubai’

$filter=startswith(Name,'dubai')

Example: all Account with a Name  19 characters Length

$filter=length(Name) eq 19

Example: all Account with a Name containing ‘Dubai’ starting at the second character Index

$filter=indexof(Name,'Dubai') eq 1

Example: all Account with a Name that equals ‘manish chouhan’ once any uppercase characters have been converted to lowercase tolower

$filter=tolower(name) eq 'manish chouhan'

Example: all Account with a Name that equals ‘MANISH CHOUHAN’ once any lowercase characters have been converted to uppercase toupper

$filter=toupper(CompanyName) eq 'MANISH CHOUHAN'

Example: all employees birth year is 1971

$filter=year(BirthDate) eq 1971

TWO: Order BY ($orderby) in list Records action to fetch records in Particular Order

ODATA : https://dvmske0.crm8.dynamics.com/api/data/v9.1/accounts?$orderby=name desc

https://i0.wp.com/microsoftdynamics.in/wp-content/uploads/2020/06/img_5ee543f37eae2.png?fit=1532%2C672&ssl=1

Power Automate: List records action, select environment, and Entity with  ODATA Filter as “$orderby=name desc

https://i0.wp.com/microsoftdynamics.in/wp-content/uploads/2020/06/img_5ee5444bb8824.png?fit=1621%2C379&ssl=1

Click Here Three: Expend ($Expand) in list records action to pull Related Entity and apply $select to specify Attribute of the related entity i.e

$expand=primarycontactid($select=fullname)
$expand=primarycontactid$filter=emailaddress1 eq null)

Example: Expand Contact entity, simple primary contact lookup i.e $expand=primarycontactid

Example: Expand Contact entity, simple primary contact lookup with filtering $expand=primarycontactid($filter=emailaddress1 eq null)

Click Here Click Here for full post
https://i0.wp.com/microsoftdynamics.in/wp-content/uploads/2020/06/img_5ee5dbd944f08.png?fit=1475%2C415&ssl=1
https://i0.wp.com/microsoftdynamics.in/wp-content/uploads/2020/04/Microsoftdynamics365.png?fit=640%2C651&ssl=1
Microsoft Dynamics Community Profile

Learn more