using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.Xrm.Sdk; namespace SamplePlugin { public class Plugin : IPlugin { public void Execute(IServiceProvider serviceProvider) { IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext)); IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory)); IOrganizationService orgService = factory.CreateOrganizationService(null); Entity target = (Entity)context.InputParameters["Target"]; //Some Actions target["Field"] = "Value"; orgService.Update(target); } } }
The key points to reproduce error are:
1. Plugin should be registered to handle Create message in Synchronous Post-Operation mode.
2. Entity should be emailable (like contact, account or lead).
3. Email address should be filled at creation form.
Here are possible ways out to solve this issue:
1. For lazy guys who don’t want to update, rebuild and redeploy plugins the way out is to register plugin as Asynchronous.
2. For developers who are not afraid to redesign code it is possible to use following approach:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.Xrm.Sdk; namespace SamplePlugin { public class Plugin : IPlugin { public void Execute(IServiceProvider serviceProvider) { IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext)); IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory)); IOrganizationService orgService = factory.CreateOrganizationService(null); Entity target = (Entity)context.InputParameters["Target"]; //Some Actions Entity updatedTarget = new Entity(target.LogicalName) { Id = target.Id }; updatedTarget["Field"] = "Value"; orgService.Update(updatedTarget); } } }
In case you would not choose 2-nd way you should know about side affect of first approach – plugins that handle Update message for some fields that were passed to current plugin context would be triggered.
What if you need to update specifically the email field and have a plugin registered with the email field in the filter attributes ?
Then the only way unfortunately – you will have to go Async execution way.
Thank you for the information! we hit the same problem.
Welcome!
Thanks a lot!!
Welcome!
Hello Andrii.
I have faced the same issue but with Dynamics 365 (9.0) Online.
In My case i’m creating account records from external web service (integration service). I don’t know how to fix this issue.
It occures whe I’m creating account with emailaddress1 filled.
With empty value all works fine.
Only one way helps me: create account without emailaddress1 then update it.
Do you have any update about this issue?
Thank you in advanced.
Serhii, do you have any plugins that handle Create message?
I have no plugins for this entity. Only default ActivityFeeds. But I tried to disable it and create new account. The same…
That’s why this issue so strange.
The way of creation and updating look like workaround in my case but it shouldn’t work like this 🙁
3 more questions – have you tried to create a record just from UI? Do you experience same issues?
Is there a chance that you have real-time workflows that handle create event of accounts?
What ‘s the exact exception do you get? Is it “Generic SQL exception”?
Andrii,
1) ui works
2) there are no any other kind of process
3) generic sql error
Serhii,
I believe that the last resort for you is to open support ticket with Microsoft and ask for explanation. BTW I experienced several weird floating issues with 9.0 in several environments so that could be another “floating” bug.