Wednesday, October 02, 2013

Code snippet to add to marketing list

Use the code template from here
string[] cust_str = {"000000XXXXX"};
                     ConditionExpression con_ce1 = new ConditionExpression("efs_sourcecustomernumber", ConditionOperator.In, cust_str);
                     FilterExpression con_fe = new FilterExpression(LogicalOperator.And);
                     QueryExpression con_qe = new QueryExpression();
                     con_qe.EntityName = "contact";
                     con_qe.Criteria = con_fe;
                     con_qe.ColumnSet = new ColumnSet("contactid", "efs_sourcecustomernumber");
                     con_qe.PageInfo.ReturnTotalRecordCount = true;
                     EntityCollection con_coll = _service.RetrieveMultiple(con_qe);

                     foreach (Entity ent in con_coll.Entities)
                         AddMemberListRequest req = new AddMemberListRequest();
                         //we will add an account to our marketing list
                         //entity type must be an account, contact, or lead
                         req.EntityId = ent.Id;
                         //we will add the account to this existing marketing list
                         //Morgenmøte NL
                         req.ListId = new Guid("22F69F49-360A-E311-8620-0050568E0699");
                         AddMemberListResponse resp = (AddMemberListResponse)_service.Execute(req);

No comments: