Protected Overrides Function Execute(ByVal executionContext As ActivityExecutionContext) As ActivityExecutionStatus
' Set default NULL values for output properties
Me.Contact.IsNull = True
Me.Contact.IsNullSpecified = True
Me.Account.IsNull = True
Me.Account.IsNullSpecified = True
Me.Lead.IsNull = True
Me.Lead.IsNullSpecified = True
Me.User.IsNull = True
Me.User.IsNullSpecified = True
Me.Queue.IsNull = True
Me.Queue.IsNullSpecified = True
' Get the context service
Dim contextService As IContextService = CType(executionContext.GetService(GetType(IContextService)), IContextService)
' Get the context
Dim context As IWorkflowContext = contextService.Context
' Create an instance of CrmService
Dim service As ICrmService = context.CreateCrmService
' Make sure that the input lookup field has been specified
If Not (Email Is Nothing) Then
' Make sure that the input lookup field is of type "email"
If Email.type = "email" Then
' Initalise the TargetRetrieveEmail class
Dim target As New Microsoft.Crm.SdkTypeProxy.TargetRetrieveEmail
' Set the EntityId property equal to the E-mail Id
target.EntityId = Email.Value
' Only retrieve the "from" attribute of the "email" entity
Dim columnSet As New Microsoft.Crm.Sdk.Query.ColumnSet
columnSet.AddColumns(New String() {"from"})
' Initialise the RetrieveRequest class
Dim request As New Microsoft.Crm.SdkTypeProxy.RetrieveRequest
request.Target = target
request.ColumnSet = columnSet
' Call the CRM web service to retrieve the email entity
Dim response As RetrieveResponse = service.Execute(request)
Dim emailEntity As Microsoft.Crm.SdkTypeProxy.email = CType(response.BusinessEntity, Microsoft.Crm.SdkTypeProxy.email)
' email.from is a array of type "microsoft.crm.sdktypeproxy.activityparty"
Dim fromAttribute() As Microsoft.Crm.SdkTypeProxy.activityparty = emailEntity.from
' Determine the entity type of the first activityparty
' Return the correct entity type
If Not (fromAttribute Is Nothing) Then
If Not (fromAttribute(0) Is Nothing) Then
If Not (fromAttribute(0).partyid Is Nothing) Then
Select Case fromAttribute(0).partyid.type
Case "contact"
Me.Contact = fromAttribute(0).partyid
Case "account"
Me.Account = fromAttribute(0).partyid
Case "lead"
Me.Lead = fromAttribute(0).partyid
Case "systemuser"
Me.User = fromAttribute(0).partyid
Case "queue"
Me.Queue = fromAttribute(0).partyid
End Select
End If
End If
End If
End If
End If
' Set up return parameter
Return ActivityExecutionStatus.Closed
End Function