Menu Close

Blog

Slide 1

Microsoft Business Applications Blogposts, YouTube Videos and Podcasts

Helping Businesses with Technology

Slide 2

Microsoft Business Applications Blogposts, YouTube Videos and Podcasts

Helping Businesses with Technology

Slide 3

Microsoft Business Applications Blogposts, YouTube Videos and Podcasts

Helping Businesses with Technology

previous arrow
next arrow

SYNTAX CHANGES FROM MS CRM 4.0 TO CRM 2011 PLUGINS

                  SYNTAX CHANGES FROM MS CRM 4.0 TO CRM 2011 PLUGINS

There are number of changes between Dynamics CRM 2011 SDK and CRM 4 SDK. Let’s take a look at what has changed between plugins.
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)
serviceProvider.GetService(typeof(Microsoft.Xrm.Sdk.IPluginExecutionContext));
4. ICrmService has been changed to IOrganizationService.
ICrmService sdk = context.CreateCrmService(true);
IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService sdk = factory.CreateOrganizationService(context.UserId);
5. DynamicEntity has been changed to Entity.
    ·         Properties property of DynamicEntity no longer exists
    ·         Getting and Setting values no longer use *Property classes, 
      eg: no more KeyProperty, StringProperty…etc, simply do int value = (int)entity[“schema_name”];
if (context.InputParameters.Properties.Contains("Target") && 
context.InputParameters.Properties["Target"is DynamicEntity)
if (context.InputParameters.Contains("Target") &&
context.InputParameters["Target"is Entity)
Share this:

DIFFERENCE BETWEEN CRM 4.0 AND CRM 2011 CUSTOM WORKFLOW

CRM 2011 – Custom Workflow Syntax changes from CRM 4 to CRM 2011

CRM 4.0
using System.Workflow.Activities;
using System.Workflow.ComponentModel;
using System.Workflow.ComponentModel.Compiler;
using Microsoft.Crm.Sdk;
using Microsoft.Crm.Sdk.Query;
using Microsoft.Crm.SdkTypeProxy;
using Microsoft.Crm.Workflow;
CRM 2011
using System.Activities;
using Microsoft.Crm.Sdk.Messages;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Workflow;
2. Base Class
Base class definition has been changed from  SequenceActivity to CodeActivity.
CRM 4.0: In CRM 4.0 we have to specify both Workflow name and Workflowactivitygroupname in the code as written in the following code.
[CrmWorkflowActivity(“My Custom Workflow”, “CRM Workflow”)]
public class MyCustomWF: SequenceActivity
CRM 2011: In CRM 2011 that is done in different way.
public class MyCustomWF: CodeActivity
Both Workflow name and Workflowactivitygroupname can be specified at the time of registering the assembly as shown in below screen shot.
3. Execute Method
The overridden Execute method remains the same except parameter and return type.
CRM 4.0
protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
CRM 2011
protected override void Execute(CodeActivityContext executionContext)
4. Create service
CRM 4.0
IContextService contextService = (IContextService)executionContext.GetService(typeof(IContextService));
IWorkflowContext context = contextService.Context;
ICrmService crmService = context.CreateCrmService();
CRM 2011
IWorkflowContext context = executionContext.GetExtension<IWorkflowContext>();
IOrganizationServiceFactory serviceFactory = executionContext.GetExtension<IOrganizationServiceFactory>();
IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
5. INPUT Parameters
CRM 4.0
Declaration: how to initialize the input parameter
// specified dependency property
public static DependencyProperty CaseIDProperty = DependencyProperty.Register(“CaseID”, typeof(Lookup), typeof(TotalTaskRetrieval));
// Specified Input property
[CrmInput(“Enter Case “)]
// Set the reference Target for Property created
[CrmReferenceTarget(“incident”)]
// Property Defined for caseId
public Lookup CaseID
{
get
{
return (Lookup)base.GetValue(CaseIDProperty);
}
set
{
base.SetValue(CaseIDProperty, value);
}
}
Use: Access the input parameter declared above as,
Guid caseid=CaseID.Value
CRM 2011
Declaration: how to initialize the input parameter
[Input(“Enter Case “)]
[ReferenceTarget(“incident “)]
[Default(“3B036E3E-94F9-DE11-B508-00155DBA2902″, ” incident “)]
public InArgument<EntityReference> CaseID { get; set; }
Use: Access the input parameter declared above as,
Guid caseid = CaseID.Get<EntityReference>(executionContext).Id
6. OUTPUT  Parameters
CRM 4.0
[CrmOutput(“outputSum”)]
public CrmMoney Sum
{
get
{
return (CrmMoney)base.GetValue(SumProperty);
}
set
{
base.SetValue(SumProperty , value);
}
}
CRM 2011
[Output(“outputSum”)]
[Default(“23.3”)]
public OutArgument<Money> Sum { get; set; }
Share this:

ACTIVATE AND DEACTIVATE THE CONTACT RECORD IN MS CRM 2013

ACTIVATE AND DEACTIVATE THE CONTACT AND DEACTIVATE/ACTIVATE FROM ITS PRIMARY ACCOUNT IN MS CRM 2013

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;



}

}

}

}

Share this:

BUSINESS ERROR AFTER SOLUTION DEPLOYED ON TO PRODUCTION MS CRM 2013

PRODUCTION ERROR IN MS CRM 2013

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:-) 

Share this:

CRM 2011 Developer Tools target location for Visual Studio 2010 vs Visual Studio 2012

CRM 2011 Developer Tools target location for Visual Studio 2010 vs Visual Studio 2012

  

The path for the targets is different for the Developer Toolkit for Visual Studio 2010 and Visual Studio 2012. This can cause errors when loading the Visual Studio project in the form of the error

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:

  1. In Visual Studio, right click the CrmPackage project and click Unload Project.
  2. Right click on the CrmPackage project and click edit CrmPackage.csproj.
  3. Find the line starting with “<Import Project=”$(MSBuildExtensionsPath32)MicrosoftCRM” and replace it with the correct path from the list below.
  4. Save and close the file.
  5. Right click on the CrmPackage project and click Reload Project.
Visual Studio 2010
<Import Project="$(MSBuildExtensionsPath32)MicrosoftCRMMicrosoft.CrmDeveloperTools.CrmClient.targets" />
Visual Studio 2012
<Import Project="$(MSBuildExtensionsPath32)MicrosoftCRMMicrosoft.CrmDeveloperTools.12.targets" />
Share this: