Hello,
i have a problem to create records on relationship N-N with a plugin on POST Create contact.
I want copy all contacts on a relationship N-N with accounts.
I have created N-N on CRM. On the database, i see a new table new_contact_accountBase(contains new_contactaccountid,version number,contactid,accountid)
I retrieve all account and for each i want created a record on this table with accountid and contactid. but i have an error
Server was unable to process request.Itryto retrievemultiple on this new_contact_account but same error.
Here my code:
Dim
contactId As Guid = context.OutputParameters("id")
Dim service As ICrmService = CType(context.CreateCrmService(False), ICrmService)
Dim indice As Integer
Dim info_contact As New contact
info_contact = service.Retrieve(EntityName.contact.ToString, contactId,
New AllColumns)
Dim accounts As BusinessEntityCollection
Dim query As New QueryExpression
query.ColumnSet =
New AllColumns
query.EntityName = EntityName.account.ToString
accounts = service.RetrieveMultiple(query)
For indice = 0 To accounts.BusinessEntities.Count - 1
Dim account_detail As account
account_detail = accounts.BusinessEntities.Item(indice)
Dim contactnn As New DynamicEntity
contactnn.Name = "new_contact_account"
Dim collection_property As New PropertyCollection
Dim id_contact As New LookupProperty
id_contact.Name =
"contactid"
id_contact.Value =
New Lookup(EntityName.contact.ToString, contactId)
Dim id_account As New LookupProperty
id_account.Name =
"accountid"
id_account.Value =
New Lookup(EntityName.account.ToString, account_detail.accountid.Value)
collection_property.Add(id_contact)
collection_property.Add(id_account)
contactnn.Properties = collection_property
Dim mytarget As New TargetCreateDynamic
mytarget.Entity = contactnn
Dim create As New CreateRequest
create.Target = mytarget
Dim myresponse As New CreateResponse
myresponse = service.Execute(create)
Next indice
Thanks for your help.