1. The IPlugin now resides in Microsoft.Xrm.Sdk namespace instead of Microsoft.Crm.Sdk |
|
public class ClassName : Microsoft.Crm.Sdk.IPluginpublic class ClassName : Microsoft.Xrm.Sdk.IPlugin |
|
2. The Execute method signature of the IPlugin interface has changed, it now expects an IServiceProvider instead of the IPluginExecutionContext. |
|
public void Execute(IPluginExecutionContext context)public void Execute(IServiceProvider serviceProvider) |
|
3. To get a reference to the IPluginExecutionContext you now need to call the GetService method of the IServiceProvider interface. |
|
public void Execute(IPluginExecutionContext context)Microsoft.Xrm.Sdk.IPluginExecutionContext context =(Microsoft.Xrm.Sdk.IPluginExecutionContext) |
|
4. ICrmService has been changed to IOrganizationService. |
|
ICrmService sdk = context.CreateCrmService(true); IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory)); |
|
5. DynamicEntity has been changed to Entity. eg: no more KeyProperty, StringProperty…etc, simply do int value = (int)entity[“schema_name”]; |
|
if (context.InputParameters.Properties.Contains("Target") && if (context.InputParameters.Contains("Target") && |
CRM 2011 – Custom Workflow Syntax changes from CRM 4 to CRM 2011
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Query;
namespace UltimaDisplay2016
{public class DeactivateContact : IPlugin
{
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);
try
{
if((context.InputParameters.Contains(“EntityMoniker”))&&(context.InputParameters[“EntityMoniker”] is EntityReference))
{
var targetEntity = (EntityReference)context.InputParameters[“EntityMoniker”];
var state = (OptionSetValue)context.InputParameters[“state”];
var status = (OptionSetValue)context.InputParameters[“status”];
if(targetEntity.LogicalName != “contact”)
{
return;
}
if(state.Value == 1)
{
Guid contactId = targetEntity.Id;
Entity account = new Entity(“account”);
// to fetch account details
EntityCollection entitycollection = getAccountDetails(contactId, service);
foreach(Entity entity in entitycollection.Entities)
{
entity.Attributes[“primarycontactid”] = null;
service.Update(entity);
}
}
else
{
return;
}
}
}
catch (Exception)
{
throw;
}
}
// Fetching the record
public EntityCollection getAccountDetails(Guid contactId,IOrganizationService service)
{
try
{
string fetchXML = @”<fetch distinct=’false’ mapping=’logical’ output-format=’xml-platform’ version=’1.0′>
<entity name=’account’>
<attribute name=’name’/>
<attribute name=’accountid’/>
<filter type=’and’>
<condition attribute=’primarycontactid’ value='{0}’ uitype=’contact’ operator=’eq’/>
</filter>
</entity>
</fetch>”;
string fetch = string.Format(fetchXML, contactId);
EntityCollection collection = service.RetrieveMultiple(new FetchExpression(fetch));
return collection;
}
catch(Exception)
{
throw;
}
}
}
}
Hi All,
I have came across a situation where i have deployed the Managed solution on the Onpremises MS CRM 2013 Production Environment for one of my client.
It came up “Business Error” when the users trying to update the Account record.
After quick glance, i figure out the problem is in the new solution which i have deployed, as the new solution have some entities and the production users don’t have access to them.
Go to Settings > Administration > Security Roles > Business Development(Security role name) >
Select the “Custom Entities” then select the new entities and set permissions for the security role.
Hence the problem has been resolved.
I Hope This Helps
Cheers:-)
CRM 2011 Developer Tools target location for Visual Studio 2010 vs Visual Studio 2012
The imported project “C:Program Files (x86)MSBuildMicrosoftCRMMicrosoft.CrmDeveloperTools.CrmClient.targets” was not found. Confirm that the path in the declaration is correct, and that the file exists on disk.
or when attempting to deploy the CrmPackage project from Visual Studio 2010 as the error
Error connecting to CRM Server. [A]Microsoft.CrmDeveloperTools.CrmClient.Entities.Solution cannot be cast to [B]Microsoft.CrmDeveloperTools.CrmClient.Entities.Solution. Type A originates from ‘Microsoft.CrmDeveloperTools.CrmClient, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35’ in the context ‘LoadFrom’ at location ‘C:Program Files (x86)Microsoft Visual Studio 10.0Common7IDEExtensionsMicrosoftDynamics CRM 2011 Developer Tools1.0Microsoft.CrmDeveloperTools.CrmClient.dll’. Type B originates from ‘Microsoft.CrmDeveloperTools, Version=1.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35’ in the context ‘LoadFrom’ at location ‘C:Program Files (x86)MSBuildMicrosoftCRMMicrosoft.CrmDeveloperTools.dll’.
or when attempting to deploy the CrmPackage project from Visual Studio 2012 as the error
Error connecting to CRM Server. [A]Microsoft.CrmDeveloperTools.CrmClient.Entities.Solution cannot be cast to [B]Microsoft.CrmDeveloperTools.CrmClient.Entities.Solution. Type A originates from ‘Microsoft.CrmDeveloperTools, Version=1.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35’ in the context ‘LoadFrom’ at location ‘C:Program Files (x86)Microsoft Visual Studio 11.0Common7IDEExtensionsMicrosoftDynamics CRM 2011 Developer Tools1.0Microsoft.CrmDeveloperTools.dll’. Type B originates from ‘Microsoft.CrmDeveloperTools.CrmClient, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35’ in the context ‘LoadFrom’ at location ‘C:Program Files (x86)MSBuildMicrosoftCRMMicrosoft.CrmDeveloperTools.CrmClient.dll’.
depending on the combination of Visual Studio version, installed Developer Toolkit version and previously installed Developer Toolkit versions.
In order to resolve any of these, make sure that the correct targets are referenced in the CrmPackage.csproj file:
- In Visual Studio, right click the CrmPackage project and click Unload Project.
- Right click on the CrmPackage project and click edit CrmPackage.csproj.
- Find the line starting with “<Import Project=”$(MSBuildExtensionsPath32)MicrosoftCRM” and replace it with the correct path from the list below.
- Save and close the file.
- Right click on the CrmPackage project and click Reload Project.
< Import Project = "$(MSBuildExtensionsPath32)MicrosoftCRMMicrosoft.CrmDeveloperTools.CrmClient.targets" /> |
< Import Project = "$(MSBuildExtensionsPath32)MicrosoftCRMMicrosoft.CrmDeveloperTools.12.targets" /> |