
Hey all,
Thought this would be super simple but I am running into some walls. Any help would be appreciated:
Requirement:
Background:
Thanks for taking the time to help me resolve this issue. Any thoughts would be helpful. So here goes:
Hi Anthony,
You can register a plugin on pre-create and pre-update of contact record which extracts domain name from email address and set to another field in contact.
Below code is for your reference
using System.Net.Mail;
public void Execute(IServiceProvider serviceProvider)
{
IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
{
Entity entity = (Entity)context.InputParameters["Target"];
if (entity.LogicalName.Equals("contact"))
{
string emailAddress = entity.Contains("emailaddress1") ? entity.GetAttributeValue("emailaddress1") : string.Empty;
if (string.IsNullOrEmpty(emailAddress))
{
MailAddress address = new MailAddress("xyz@dynamics.com");
string host = address.Host;
entity.Attributes["new_emaildomain"] = host;
}
}
}
}