Wednesday 9 August 2017

CRUD with Odata and Data entities in Dynamics 365 for operations - READ Operations-3

....contnd from part 2

7.use of logical operators

i.) NOT
https://*******devaos.cloudax.dynamics.com/data/Beaconservice?$filter=not(BeaconNum eq '123456789')

OR

https://********devaos.cloudax.dynamics.com/data/Beaconservice?$filter=BeaconNum ne '123456789'


{
    "@odata.context": "https://********devaos.cloudax.dynamics.com/data/$metadata#Beaconservice",
    "value": [
        {
            "@odata.etag": "W/\"Jzg0ODAyMzczOCw1NjM3MTQ0NTc3Jw==\"",
            "Description": "Beacon 2",
            "dataAreaId": "usrt",
            "BeaconNum": "234567891",
            "EffectiveDate": "2017-01-08T12:00:00Z",
            "BeaconStatus": "InActive",
            "Brand": "Brand2",
            "StartTime": 0,
            "Category": "Category2",
            "EndTime": 0,
            "Offer": "",
            "OfferId": "offer2"
        },
        {
            "@odata.etag": "W/\"JzEsNTYzNzE0NDU3OCc=\"",
            "Description": "Beacon 3",
            "dataAreaId": "usrt",
            "BeaconNum": "345678912",
            "EffectiveDate": "2017-05-08T12:00:00Z",
            "BeaconStatus": "Active",
            "Brand": "Brand3",
            "StartTime": 0,
            "Category": "Category3",
            "EndTime": 0,
            "Offer": "",
            "OfferId": "Offer3"
        }
    ]
}

ii.) CONTAINS(*)
https://*********devaos.cloudax.dynamics.com/data/Beaconservice?$filter=BeaconNum eq '*9'



{
    "@odata.context": "https://**********devaos.cloudax.dynamics.com/data/$metadata#Beaconservice",
    "value": [
        {
            "@odata.etag": "W/\"JzE0NTk5MjkxNjcsNTYzNzE0NDU3Nic=\"",
            "Description": "beacon 1",
            "dataAreaId": "usrt",
            "BeaconNum": "123456789",
            "EffectiveDate": "2017-01-08T12:00:00Z",
            "BeaconStatus": "Active",
            "Brand": "Brand1",
            "StartTime": 0,
            "Category": "Category1",
            "EndTime": 0,
            "Offer": "",
            "OfferId": "Offer1"
        }
    ]
}

iii.) AND
https://********devaos.cloudax.dynamics.com/data/Beaconservice?$filter=BeaconNum eq '345678912' and OfferId eq 'Offer3'
{
    "@odata.context": "https://*******devaos.cloudax.dynamics.com/data/$metadata#Beaconservice",
    "value": [
        {
            "@odata.etag": "W/\"JzEsNTYzNzE0NDU3OCc=\"",
            "Description": "Beacon 3",
            "dataAreaId": "usrt",
            "BeaconNum": "345678912",
            "EffectiveDate": "2017-05-08T12:00:00Z",
            "BeaconStatus": "Active",
            "Brand": "Brand3",
            "StartTime": 0,
            "Category": "Category3",
            "EndTime": 0,
            "Offer": "",
            "OfferId": "Offer3"
        }
    ]
}

iv.) OR
https://*********devaos.cloudax.dynamics.com/data/Beaconservice?$filter=BeaconNum eq '345678912' or BeaconNum eq '123456789'
{
    "@odata.context": "https://********devaos.cloudax.dynamics.com/data/$metadata#Beaconservice",
    "value": [
        {
            "@odata.etag": "W/\"JzE0NTk5MjkxNjcsNTYzNzE0NDU3Nic=\"",
            "Description": "beacon 1",
            "dataAreaId": "usrt",
            "BeaconNum": "123456789",
            "EffectiveDate": "2017-01-08T12:00:00Z",
            "BeaconStatus": "Active",
            "Brand": "Brand1",
            "StartTime": 0,
            "Category": "Category1",
            "EndTime": 0,
            "Offer": "",
            "OfferId": "Offer1"
        },
        {
            "@odata.etag": "W/\"JzEsNTYzNzE0NDU3OCc=\"",
            "Description": "Beacon 3",
            "dataAreaId": "usrt",
            "BeaconNum": "345678912",
            "EffectiveDate": "2017-05-08T12:00:00Z",
            "BeaconStatus": "Active",
            "Brand": "Brand3",
            "StartTime": 0,
            "Category": "Category3",
            "EndTime": 0,
            "Offer": "",
            "OfferId": "Offer3"
        }
    ]
}

Other than the operators explained, below mentioned logical operators can be used in a same manner.

v.)Greater Than(gt)
vi.)Greater Than or Equal(ge)
vii.)Less Than(lt)
viii.)Less Than or Equal(le)

There are some arithmetic operators that can be used on integer/real type fields to produce result.

xi.) ADDITION (add)
x.)SUBTRACTION (sub)
xi.)MULTIPLICATION (mul)
xii.)DIVISION (div)

Then there is one more operator that has to be used extensively.

AMPERSAND(&)
There might be situations when you need to use previously explained query operators(filter, select, etc..) together to produce relevant set of data.

https://**********devaos.cloudax.dynamics.com/data/Beaconservice?$filter=BeaconNum eq '345678912' &$select=BeaconNum,Description,OfferId


{
    "@odata.context": "https://*********devaos.cloudax.dynamics.com/data/$metadata#Beaconservice(BeaconNum,Description,OfferId)",
    "value": [
        {
            "@odata.etag": "W/\"JzEsNTYzNzE0NDU3OCc=\"",
            "BeaconNum": "345678912",
            "Description": "Beacon 3",
            "OfferId": "Offer3"
        }
    ]
}

This was my last post on READ operations. On Next blog, I will be discussing about remaining operations of CREATE, UPDATE and DELETE.

Not to mention, I welcome any suggestion or queries on this post.

2 comments:

  1. hey, this is a wonderful blog post. well written. thanks for sharing. did you ever complete the blog about the CREATE, UPDATE against the entities?

    ReplyDelete
    Replies
    1. Thanks for your appreciation...I will be publishing the other things soon.. :)

      Delete