Quantcast
Channel: Microsoft Dynamics CRM Forum - Recent Threads
Viewing all articles
Browse latest Browse all 46379

Bulk Contact merge using console application

$
0
0

Hi I am trying to use the below code to contact merge ,

but this code gives only for text field how about two options ,optionset values and date values


for example if the master contact record has one field(attribute) with flag yes or no, for this how we do validate for subordinate record and master record and how do we assign that value from subordinate record to master record, please help for the option set values and date values as well.

publicvoidMergeAccounts(Guid masterAccountId, Guid subOrdinateAccountId)
       {
           try
           {
               //Create CRM Connection       
               IOrganizationService crmConnection = GetCRMConnection();
 
               //Create the target for the request.       
               EntityReference target = newEntityReference();
 
               //Id is the GUID of the account that is being merged into.       
               //LogicalName is the type of the entity being merged to, as a string       
               target.Id = masterAccountId;
               target.LogicalName = "account";
 
               //Create the request.       
               MergeRequest merge = newMergeRequest();
 
               // SubordinateId is the GUID of the account merging.   
               merge.SubordinateId = subOrdinateAccountId;
               merge.Target = target;
               merge.PerformParentingChecks = false;
               Entity updateContent = newEntity("account");
               varcols = newColumnSet(new[] { "primarycontactid", "websiteurl", "telephone1", "fax", "emailaddress1"});
 
               //Get Master Account Primary Contact,Website,Phone,Fax,Email
               varmasterAccount = crmConnection.Retrieve("account", masterAccountId, cols);
 
               //Get Subordinate Account Primary Contact,Website,Phone,Fax,Email
               varsubOrdinateAccount = crmConnection.Retrieve("account", subOrdinateAccountId, cols);
 
               //If PrimaryContact,Website,Phone,Fax,Email fields data are populated on the Subordinate Account and NOT populated on the Master Account. updated these Subordinate account values to the Master record.                 
               if(!masterAccount.Contains("primarycontactid") && subOrdinateAccount.Contains("primarycontactid"))
                   updateContent.Attributes.Add("primarycontactid", newEntityReference("contact", subOrdinateAccount.GetAttributeValue<EntityReference>("primarycontactid").Id));
 
               if(!masterAccount.Contains("websiteurl") && subOrdinateAccount.Contains("websiteurl"))
                   updateContent.Attributes.Add("websiteurl", subOrdinateAccount.Attributes["websiteurl"]);
 
               if(!masterAccount.Contains("telephone1") && subOrdinateAccount.Contains("telephone1"))
                   updateContent.Attributes.Add("telephone1", subOrdinateAccount.Attributes["telephone1"]);
 
               if(!masterAccount.Contains("fax") && subOrdinateAccount.Contains("fax"))
                   updateContent.Attributes.Add("fax", subOrdinateAccount.Attributes["fax"]);
 
               if(!masterAccount.Contains("emailaddress1") && subOrdinateAccount.Contains("emailaddress1"))
                   updateContent.Attributes.Add("emailaddress1", subOrdinateAccount.Attributes["emailaddress1"]);
 
               merge.UpdateContent = updateContent;
 
               // Execute the request.  
               MergeResponse mergeRes = (MergeResponse)crmConnection.Execute(merge);
           }
           catch(Exception ex)
           {
               //Throw the exception       
               throwex;
           }

 Kindly help me here 


Viewing all articles
Browse latest Browse all 46379

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>