I'm trying to write a SQLCRL database project to sync our legacy SQL application to our CRM. I have been given lots of help so far all which has helped a lot, so thank you. I have tried to apply what I have been taught to this current problem.
The scenario is that each customer has a unique licence number and this is used in the 'name' field in accounts.
I have a custom entity call new_clientoaccounts. new_clientoaccounts has a lookup field called new_licence which is a N-1 lookup on accounts. (new_clientoaccounts = N , accounts = 1 ) on accounts 'name'
in new_clientoaccounts each customer may have multiple records. Each customer record in new_clientoaccounts has a sequential number stored as a string ie 001,002 003, etc stored in new new_oaccountclientid
What I am trying to do is update a new_clientoaccounts based on new_licence and new_new_oaccountclientid. My code so far
<Microsoft.SqlServer.Server.SqlProcedure()> _ Public Shared Sub OriginatingAccount_Update(LicenceNo As SqlString, sOaccountId As SqlString, OaccountClientId As SqlString, Country As SqlString, BACSID As SqlString, Sortcode As SqlString, AccountNumber As SqlString, AccountName As SqlString, Allowpayments As SqlBoolean, AllowDebits As SqlBoolean, AccountActive As SqlBoolean) Dim token As New CrmAuthenticationToken() token.AuthenticationType = 0 token.OrganizationName = "XXX" Using crmService As New CrmService() Try Dim YesBoolean As New CrmBoolean Dim NoBoolean As New CrmBoolean YesBoolean.Value = True NoBoolean.Value = False crmService.Url = "https://XXX.XXXX.XX:XXX/MSCRMServices/2007/CrmService.asmx" crmService.Credentials = New System.Net.NetworkCredential("XXX", XXX", "XX") crmService.CrmAuthenticationTokenValue = token crmService.UnsafeAuthenticatedConnectionSharing = True crmService.PreAuthenticate = True Dim _queryattr As New QueryByAttribute() _queryattr.EntityName = "account" Dim _columns As New ColumnSet() _columns.Attributes = New String() {"accountid"} _queryattr.ColumnSet = _columns _queryattr.Attributes = New String() {"name"} _queryattr.Values = New String() {LicenceNo.Value} Dim accountResultSet As BusinessEntityCollection = crmService.RetrieveMultiple(_queryattr) Dim AccountID As String = String.Empty For Each aAccount As account In accountResultSet.BusinessEntities AccountID = aAccount.accountid.Value.ToString Using sw As New StreamWriter(LOGFilePath & "trig_Oaccounts_Update.txt", True) sw.WriteLine(LicenceNo.Value.ToString & " ----- " & aAccount.accountid.Value.ToString) End Using Dim _oqueryattr As New QueryByAttribute() _oqueryattr.EntityName = "new_clientoaccounts" Dim _ocolumns As New ColumnSet() _ocolumns.Attributes = New String() {"new_clientoaccountsid"} _oqueryattr.ColumnSet = _ocolumns _oqueryattr.Attributes = New String() {"new_licence"} _oqueryattr.Values = New String() {aAccount.accountid.Value.ToString} _oqueryattr.Attributes = New String() {"new_oaccountclientid"} _oqueryattr.Values = New String() {"002"} Dim oaccountResultSet As BusinessEntityCollection = crmService.RetrieveMultiple(_oqueryattr) For Each oAccount As new_clientoaccounts In oaccountResultSet.BusinessEntities Using sw As New StreamWriter(LOGFilePath & "trig_Oaccounts_Update.txt", True) sw.WriteLine(LicenceNo.Value.ToString & " ----- " & oAccount.new_accountname.ToString) End Using Exit For Next Exit For Next Catch ex As Exception Using sw As New StreamWriter(LOGFilePath & "trig_Oaccounts_Update.txt", True) sw.WriteLine(LicenceNo.Value.ToString & " ----- " & ex.Message.ToString) End Using End Try End Using End Sub
At the moment Im just trying to get the new_AccountName, so at least i know i have the right New_clientoaccounid to be able to progress to the update code
This may not be the correct way of doing things, but its all I know
Dont ask me .. i dont know