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>
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
- Filter ($filter) in list Records action to fetch filtered record collection
i.e data/v9.1/accounts?$filter=statecode eq 0 - Order By ($orderby) in list Records action to fetch records in Particular Order
i.e data/v9.1/accounts?$orderby=name desc - Top ($top) Count in list Records action to fetch $top Qualifier
i.e data/v9.1/accounts?$top=5 - 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
Power Automate: List records action, select environment, and Entity with no Data filter
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
Power Automate: List records action, select environment, and Entity with ODATA Filter as “statecode eq 0”
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’
Power Automate: List records action, select environment, and Entity with ODATA Filter as “createdon gt ‘2020-06-09”
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’)
Power Automate: List records action, select environment, and Entity with ODATA Filter as “contain(subject,’refund’) or not contaains(subject,’credit’)”
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
Power Automate: List records action, select environment, and Entity with ODATA Filter as “$orderby=name desc”
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)