AXForum  
Вернуться   AXForum > Microsoft Dynamics CRM > Dynamics CRM: Blogs
All
Забыли пароль?
Зарегистрироваться Правила Справка Пользователи Сообщения за день Поиск

 
 
Опции темы Поиск в этой теме Опции просмотра
Старый 18.11.2010, 01:12   #1  
Blog bot is offline
Blog bot
Участник
 
25,631 / 848 (80) +++++++
Регистрация: 28.10.2006
Microsoft Dynamics CRM Team Blog: Upgrading a CRM 4.0 Custom Workflow Activity to CRM 2011
Источник: http://blogs.msdn.com/b/crm/archive/...-crm-2011.aspx
==============

CRM MVP Mitch Milam is our guest blogger today. Read Mitch’s blog.

I recently upgraded one of my custom workflow activity plugins to CRM 2011 and thought it would be an interesting exercise to walk through that process with you. So let’s walk through the changes, from top to bottom.

Reference Assemblies

As with any application that communicates with CRM, you need to reference the CRM SDK assemblies:

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;

Creating Parameters for the Activity

This activity accepts 4 parameters, one of which was required. In this example, we are:

  • “Decorating” a Lookup property to show the label “Marketing List” in the Workflow user interface.
  • The parameter is required
  • Since it is a lookup, the lookup is referencing the list Entity, which is a Marketing List.
CRM 4.0

With CRM 4.0 developers were generally targeting the .NET Framework v3.0 (or3.5), so to define an input parameter looked something like this:

public static DependencyProperty MarketingListLookupProperty = DependencyProperty.Register("MarketingListLookup", typeof(Lookup), typeof(RemoveFromMarketingList));   [CrmInput("Marketing List")] [ValidationOption(ValidationOption.Required)] [CrmReferenceTarget("list")] public Lookup MarketingListLookup { get { return (Lookup)base.GetValue(MarketingListLookupProperty); } set { base.SetValue(MarketingListLookupProperty, value); } }
CRM 2011

In the .NET Framework 4.0, the parameter definition is slightly condensed:

[Input("Marketing List")] [ReferenceTarget("list")] [RequiredArgument] public InArgument MarketingListEntityReference { get; set; }
Class Definition

The class definition has changed slightly due to the change in Windows Workflow versions. Beside the base class changing from SequenceActivity to CodeActivity, you will notice the CRM 2011 version does not have the “decorations” that specify the group and name that will be displayed within the CRM workflow editor. More on that later.

CRM 4.0
[CrmWorkflowActivity("Remove from Marketing List", "CRM Accelerators")]

public class RemoveFromMarketingList: SequenceActivity

CRM 2011
public class AddToMarketingList : CodeActivity

Execute Method

The Execute method remains the sole method required for a custom workflow activity though the Context parameter and return value have changed.

CRM 4.0
protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)

CRM 2011
protected override void Execute(CodeActivityContext executionContext)

Connecting to CRM

The code that defines the connection to the CrmService has changed slightly as well, but overall, the concepts remain the same:
  1. Get the Execution Context
  2. Get a handle to the Workflow Context or Organizational Service Factory
  3. Create an instance of the CrmService
CRM 4.0
IContextService contextService = (IContextService)executionContext.GetService(typeof(IContextService));

IWorkflowContext context = contextService.Context;

ICrmService crmService = context.CreateCrmService();

CRM 2011
IWorkflowContext context = executionContext.GetExtension();

IOrganizationServiceFactory serviceFactory = executionContext.GetExtension();

IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);

Accessing Parameter Values

Accessing the values found within the input parameters is slightly different in CRM 2011 where the value of the parameter is not actually extracted until you actually need to use it. In CRM 4.0, that process happens more or less automatically due to the DependencyProperty setup.

CRM 4.0
Guid ListId = MarketingListLookup.Value;

CRM 2011
Guid ListId = MarketingListEntityReference.Get(executionContext).Id;

Doing the Work

After you have all of the above code in place, the remainder of your code should function as it did in CRM 4.0. I did not have to make any changes to my code once the “plumbing” was upgraded.

Registering your Plugin

The registration process is exactly the same between versions: You use the Plugin Registration Tool.

The biggest difference between the two is in CRM 2011, the Plugin Registration Tool is where you specify how the custom workflow activity is displayed to the user within the workflow editor.

When you highlight the workflow activity, you need to specify the FriendlyName, Name, and WorkflowActivityGroupName properties as shown below:



Note: Even though the above figure doesn’t show it, the FriendlyName and Name properties need to be the same.

Conclusion

Well, that is about it. It probably only took me 2 hours to perform the upgrade of my code and that was starting from scratch with zero knowledge of the process. I just reviewed the SDK documentation and sample code and worked through each issue as it was encountered.

I hope this helps and good luck.

Mitch Milam




Источник: http://blogs.msdn.com/b/crm/archive/...-crm-2011.aspx
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.
Теги
crm online, crm2011

 

Похожие темы
Тема Автор Раздел Ответов Посл. сообщение
Microsoft Dynamics CRM Team Blog: Custom workflow actions in Microsoft Dynamics CRM 2011 Online Blog bot Dynamics CRM: Blogs 0 09.11.2010 19:05
Ошибка бизнес-процесса Tarasov E Dynamics CRM: Разработка 9 18.02.2010 14:02
CRM DE LA CREME! Configuring Microsoft Dynamics CRM 4.0 for Internet-facing deployment Blog bot Dynamics CRM: Blogs 0 18.08.2009 11:05
Microsoft Dynamics CRM Team Blog: List Web Part for Microsoft Dynamics CRM 4.0 Deployment Scenarios Blog bot Dynamics CRM: Blogs 0 30.01.2009 22:05
Microsoft Dynamics CRM Team Blog: Workflow E-mail Utilities Blog bot Dynamics CRM: Blogs 0 16.12.2008 23:05

Ваши права в разделе
Вы не можете создавать новые темы
Вы не можете отвечать в темах
Вы не можете прикреплять вложения
Вы не можете редактировать свои сообщения

BB коды Вкл.
Смайлы Вкл.
[IMG] код Вкл.
HTML код Выкл.
Быстрый переход

Рейтинг@Mail.ru
Часовой пояс GMT +3, время: 22:14.