I am looking for some guidance regarding a plugin. The plugin is to update a legacy SQL application, which seems to be straight forward enough. The plugin is fired on new_OAccount create.
I need to return a value back from the plugin into the same record.
I.e
New_Oaccount has a field new_LegacyGiud which is a text field. When a new record is added, the plugin is fired. The plugin executes a SQL stored procedure and returns back a string. I need to be able to update new_LegacyGuid with that string value
- Can this be done from the same plugin?
- If not, what would be the best way to approach this.
I have a snippit of my plugin below. The only problem I have is how to update the record that has fired the plugin
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports Microsoft.Xrm.Sdk
Imports System.ServiceModel
Imports Microsoft.SqlServer
Imports System.IO
Imports CRM2013_Plugins.clsGlobals
Imports Microsoft.Xrm.Sdk.Query
Imports Microsoft.Xrm.Sdk.Messages
Namespace OAccountsAdd
Public Class
cls_OAccounts_add
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
Dim entity As
Entity = DirectCast(context.InputParameters("Target"),
Entity)
Dim strLicence As
String = String.Empty
'new_licence()
' Get Old SQL ID
Dim SQL_Connection
As New SqlClient.SqlConnection
Dim SQL_Command As
New SqlClient.SqlCommand
Dim SQL_Return_LegacyGUID
As String = String.Empty
SQL_Connection = New SqlClient.SqlConnection(SQLConnectionString)
Try
SQL_Command.CommandType = CommandType.Text
SQL_Command.CommandText = "SELECT CAST(NEWID() as VARCHAR(50))"
SQL_Command.Connection = SQL_Connection
SQL_Connection.Open()
SQL_Return_LegacyGUID = SQL_Command.ExecuteScalar
Catch ex As
Exception
Throw New
InvalidPluginExecutionException("Error Generating GUID - " & ex.Message.ToString)
Finally
SQL_Connection.Close()
SQL_Connection.Dispose()
End Try
THIS IS WHERE I need to return the value from SQL_Return_LegacyGUID back to the new_LegacyGUID field in CRM
End
Sub
End Class
End
Namespace
Dont ask me .. i dont know