VB.NET UWP/WinRT Dynamics CRM: Find Tasks for an Incident

Back to Index

Returns tasks for a specific incident.

Documentation: https://docs.microsoft.com/en-us/dynamics365/customer-engagement/web-api/task?view=dynamics-ce-odata-9

CURL Command

curl -X GET https://my-dynamics-domain.api.crm.dynamics.com/api/data/v9.0/tasks \
  -H "Accept: application/json" \
  -H "OData-MaxVersion: 4.0"  \
  -H "OData-Version: 4.0" \
  -d "$select=subject,description,actualstart,activityid,_regardingobjectid_value" \
  -d "$filter=regardingobjectid_incident/incidentid eq c49e62a8-90df-e311-9565-a45d36fc5fe8" \
  -H "Authorization: Bearer DYNAMICS_CRM_ACCESS_TOKEN"

VB.NET UWP/WinRT Example

Dim rest As New Chilkat.Rest
Dim success As Boolean

'  URL: https://my-dynamics-domain.api.crm.dynamics.com/api/data/v9.0/tasks
Dim bTls As Boolean = True
Dim port As Integer = 443
Dim bAutoReconnect As Boolean = True
success = Await rest.ConnectAsync("my-dynamics-domain.api.crm.dynamics.com",port,bTls,bAutoReconnect)
If (success <> True) Then
    Debug.WriteLine("ConnectFailReason: " & rest.ConnectFailReason)
    Debug.WriteLine(rest.LastErrorText)
    Exit Sub
End If


rest.AddQueryParam("$select","subject,description,actualstart,activityid,_regardingobjectid_value")
rest.AddQueryParam("$filter","regardingobjectid_incident/incidentid eq c49e62a8-90df-e311-9565-a45d36fc5fe8")

rest.AddHeader("OData-MaxVersion","4.0")
rest.AddHeader("Accept","application/json")
rest.AddHeader("OData-Version","4.0")
rest.AddHeader("Authorization","Bearer DYNAMICS_CRM_ACCESS_TOKEN")

Dim sbResponseBody As New Chilkat.StringBuilder
success = Await rest.FullRequestNoBodySbAsync("GET","/api/data/v9.0/tasks",sbResponseBody)
If (success <> True) Then
    Debug.WriteLine(rest.LastErrorText)
    Exit Sub
End If

Dim respStatusCode As Integer = rest.ResponseStatusCode
If (respStatusCode >= 400) Then
    Debug.WriteLine("Response Status Code = " & respStatusCode)
    Debug.WriteLine("Response Header:")
    Debug.WriteLine(rest.ResponseHeader)
    Debug.WriteLine("Response Body:")
    Debug.WriteLine(sbResponseBody.GetAsString())
    Exit Sub
End If


Dim jsonResponse As New Chilkat.JsonObject
jsonResponse.LoadSb(sbResponseBody)

Dim i As Integer
Dim count_i As Integer

Dim odataContext As String = jsonResponse.StringOf("""@odata.context""")
i = 0
count_i = jsonResponse.SizeOfArray("value")
While i < count_i
    jsonResponse.I = i
    Dim odataEtag As String = jsonResponse.StringOf("value[i].""@odata.etag""")
    Dim subject As String = jsonResponse.StringOf("value[i].subject")
    Dim description As String = jsonResponse.StringOf("value[i].description")
    Dim actualstart As String = jsonResponse.StringOf("value[i].actualstart")
    Dim activityid As String = jsonResponse.StringOf("value[i].activityid")
    Dim v_regardingobjectid_value As String = jsonResponse.StringOf("value[i]._regardingobjectid_value")
    i = i + 1
End While

Sample JSON Response Body

{
  "@odata.context": "https://mydomain.api.crm.dynamics.com/api/data/v9.0/$metadata#tasks(subject,description,actualstart,activityid,_regardingobjectid_value)",
  "value": [
    {
      "@odata.etag": "W/\"1173836\"",
      "subject": "Feedback on the product catalog",
      "description": "Defined and captured critical customer requirements for the product catalog. Reviewed the draft content with key players on the committee; recorded attendees. Generated email using the relevant template.",
      "actualstart": null,
      "activityid": "ca81ac0c-91df-e311-b8e5-6c3be5a8b200",
      "_regardingobjectid_value": "c49e62a8-90df-e311-9565-a45d36fc5fe8"
    }
  ]
}