In a rather interesting scenario recently there was a need to validate organization name in a plugin. This was for a reusable component used for several of our clients and we wanted to make sure that the organization that can use this component is amongst our clients.
So, we needed a way to validate organization name that are using this plugin and then only allow the use of the component in case we have installed the component.
We needed a code solution!
On some research came to know about the following property in plugin context:
public void Execute(IServiceProvider serviceProvider)
{
#region initialize
IPluginExecutionContext context;
ITracingService tracingService;
IOrganizationServiceFactory serviceFactory;
IOrganizationService service;
// Get a reference to the tracing service.
tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
// Obtain the execution context from the service provider.
context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
if (context.OrganizationName != “organisationname”)
{
//Run code here
}
}
Other 2 interesting properties I wanted to tell about below:
context.IsExecutingOffline (Check if plugin is executing offline)
context.OperationCreatedOn (Check operation creation date)
Hope it helps and Happy CRMing!
If you want to know more on Dynamics CRM, just get in touch.
Do not forget to share! Sharing knowledge is true power!
![]() |
Check this out |
About the Author:
Twitter: https://twitter.com/msdynamicsblog
LinkedIn: https://www.linkedin.com/in/deepesh-somani-00296932
Google Play Store:
https://play.google.com/store/apps/details?id=com.dynamicsofdynamicscrm.msdynamicsblog&hl=en
What was the use case for branching code based on the org name?
We wanted to add an extra layer validation in plugins so that our component is only accessible for certain orgs. In actual there is no hard coding for org name but web service call to verify.
This sounds like a feature flag. I saw GOTO conference talk on the concept of feature flags to turn functionality on and off in your code. I’m experimenting with how this may be useful as a general practice in a CRM context.
Great, I will put this as a “idea portal item” soon. Good to have your inputs 🙂