Tuesday, October 25, 2016

Add Multiple Party list Users MSCRM Email in PreCreate by splitting String

Hi all,

Pleaes find the Below code for Creating Lead and Adding that user into activity party List

createLead("test;test",service,from);


        public static void createLead(string splitString, IOrganizationService service, string fieldName, Entity target)
        {
            string[] arrayfromtextEmail = splitString.Split(';');
            EntityCollection collectionEmailAddress = new EntityCollection();
            foreach (string loopWord in arrayfromtextEmail)
            {
                Guid getLeadID = checkEmailIDExisits(service, loopWord);
                if (getLeadID == Guid.Empty)
                {
                    Lead createLead = new Lead();
                    createLead.FirstName = loopWord.Substring(0, loopWord.IndexOf("@"));
                    createLead.EMailAddress1 = loopWord;
                    getLeadID = service.Create(createLead);
                }
                Entity Emailparty = new Entity(ActivityParty.EntityLogicalName);
                Emailparty["addressused"] = loopWord;
                Emailparty["partyid"] = new EntityReference(Lead.EntityLogicalName, getLeadID);
                collectionEmailAddress.Entities.Add(Emailparty);
            }
            target[fieldName] = collectionEmailAddress;
        }

No comments:

Post a Comment

Dataverse/MSCRM: Work with Masking Rule

  Introduction: In this blog, we will see how to work with Masking Rule in MSCRM or Dataverse. Issue : I don't want to show the Email va...