I have written a plugin that is fired on record create and inserts a record to a legacy SQL application. What I am trying to do is write another plugin that will update the SQL application if a record is updated in the CRM entity. From what I can work out,
when an update is made only the fields updated are passed to the plugin. I need to get all the field values from the record, to pass into the plugin.
In new_OAccounts I have a lookup new_licence, new_SUN and new_AName. new_licence will not change
If I update new_SUN, how can I get the unchanged new_licence and new_AName along with then changed new_SUN
I have tried to start this with the following code but only get an error. Please can some one help or point m in the right direction
Namespace OAccountsUpdate
Public Class cls_OAccounts_update
Implements IPlugin
Public Sub Execute(serviceProvider As System.IServiceProvider) Implements Microsoft.Xrm.Sdk.IPlugin.Execute
Dim context As IPluginExecutionContext = DirectCast(serviceProvider.GetService(GetType(IPluginExecutionContext)), IPluginExecutionContext)
If context.InputParameters.Contains("Target") AndAlso TypeOf context.InputParameters("Target") Is Entity Then
Try
Dim PreUpdateEntity As Entity = DirectCast(context.PreEntityImages("Target"), Entity)
Dim PostUpdateEntity As Entity = DirectCast(context.PostEntityImages("Target"), Entity)
Dim strLicence As String = String.Empty 'new_licence()
Dim strBACSID As String = String.Empty ' [varchar](6) NOT NULL,
Dim StrAccountName As String = String.Empty ' [varchar](32) NOT NULL,
Try
If PreUpdateEntity.Contains("new_licence") Then
Dim serviceFactory As IOrganizationServiceFactory = DirectCast(serviceProvider.GetService(GetType(IOrganizationServiceFactory)), IOrganizationServiceFactory)
Dim service As IOrganizationService = Nothing
service = serviceFactory.CreateOrganizationService(context.UserId)
Dim req As New RetrieveRequest()
req.ColumnSet = New ColumnSet(New String() {"name"})
req.Target = New EntityReference("account", DirectCast(PreUpdateEntity.Attributes("new_licence"), EntityReference).Id)
Dim resp As RetrieveResponse
resp = service.Execute(req)
strLicence = DirectCast(resp.Entity.Attributes("name"), String)
End If
Catch ex As Exception
Throw New InvalidPluginExecutionException("Error looking up Licence - " & ex.Message.ToString)
End Try
Catch ex As Exception
Throw New InvalidPluginExecutionException(ex.Message)
End Try
End If
End Sub
End Class
End Namespace
Dont ask me .. i dont know