Hi everyone,
I am trying to create a contact-marketing list using the ListMember relationship. I am getting the error "Associate is not supported for ListMember" error despite trying couple of code variations. Could you guys please advise where I am going wrong.
Method 1:
======
AssociateRequest associateRequest =newAssociateRequest{
Target =newEntityReference(Contact.EntityLogicalName, (Guid)contactId),
RelatedEntities =newEntityReferenceCollection {
newEntityReference(List.EntityLogicalName,
(Guid)context.CRMDataContext.ListSet.Where(l => l.ListName == option).Single().ListId) },
Relationship =newRelationship("listcontact_association") };
context.OrganizationService.Execute(associateRequest);
Method 2
======
Relationship List_Contact =newRelationship("listcontact_association");
EntityReference contact =newEntityReference(Contact.EntityLogicalName, (Guid)contactId);
EntityReference list =newEntityReference(List.EntityLogicalName,
(Guid)context.CRMDataContext.ListSet.Where(l => l.ListName == "List name").Single().ListId);
EntityReferenceCollection e =newEntityReferenceCollection();
e.Add(list);
context.OrganizationService.Associate("contact", (Guid)contactId, List_Contact, e);
Method 3
======
Relationship List_Contact =newRelationship("listcontact_association");
Entity Contact = context.CRMDataContext.ContactSet.Where(c => c.ContactId == contactId).Single();
Entity MarketingList = context.CRMDataContext.ListSet.Where(l => l.ListName == "List name").Single();
context.CRMDataContext.AddLink(MarketingList, List_Contact, Contact);
context.CRMDataContext.SaveChanges();
Any help is much appreciated.
Thanks.
Siva.