How to use a custom Workflow in Dynamic CRM 2011 in

Original link: http://www.cnblogs.com/csswuxi/archive/2012/11/02/2751342.html

Demand: Creating a workflow, once every three months on the implementation of CRM data to meet the requirements to be updated.

After an investigation found that the practice workflow CRM system that can be customized not be infinite loop, you can only perform 7 times.

You can only create custom VS workflow to achieve in an infinite loop, integrated into the CRM.

Implementation steps:

  1. Create a custom workflow activity, realization of CRM data updates.
  2. Create a custom workflow, implement the entire process.
  3. Custom workflow integration to CRM.

     

Create a custom workflow activity

  1. Start in the Microsoft Visual Studio 2010 .
  2. In the " File " menu, click " New " , then click the " project " .
  3. In the " New Project " dialog box " Installed Templates " pane, select "Visual C #" under " Workflow " , and then select " Activity Library " .
  4. The name and location of the solution, and then click " OK " .
  5. Navigate to the " Project " menu and select " Properties " . In the " Applications " tab, specify ".NET Framework 4" as the target framework.
  6. Add to Microsoft.Xrm.Sdk.dll and Microsoft.Xrm.Workflow.dll reference assemblies.
  7. Delete project Activity1.xaml file.
  8. The class files (.cs) to the project. In Solution Explorer, right-click the project, select " Add " , then click the " class " . In the " Add New Item " dialog box, type the name of the class, then click " Add " .
  9. Open the class file and add the following using directive:

    using System.Activities;

    using Microsoft.Xrm.Sdk;

    using Microsoft.Xrm.Sdk.Workflow;

  10. CodeActivity class inherits from the class:

    public class SampleCustomActivity : CodeActivity

  11. Add functionality class Execute method by adding:

    protected override void Execute(CodeActivityContext context)

    {

    //Activity code

    Update Data here

    }

  12. Compile the project to create an assembly (.dll) .

 

 

Create a custom workflow

To use the created or modified outside of the Microsoft Dynamics CRM XAML workflows, ensure that:

  • Your user account has in Microsoft Dynamics CRM, Deployment Administrator privileges.
  1. 在 Microsoft Dynamics CRM 服务器上启用了声明性工作流。                     PowerShell$setting.AllowDeclarativeWorkflows="True"
    								

Create a workflow project

  1. In Microsoft Visual Studio in the "File" menu, select "New" and then click on "projects."
  2. Expand the "Visual C #" under "Installed Templates" and then click "workflow."
  3. Click the "active database", select ".NET Framework 4", specify a name and location for the project, and then click "OK."
  4. In the "Solution Explorer", right-click "Activity Library", then click "Add Reference."
  5. Click "Browse" and find Microsoft.Xrm.Sdk.dll and Microsoft.Xrm.Sdk.Workflow.dll file. Select the files and add it to the project.
  6. Customized workflow.

Custom workflow integration to CRM.

Use plug-in Registration tool to register the custom workflow activity assembly to CRM.

  • Construction of Plug-in Registration tool. You can SDK \ Tools \ PluginRegistration find the source code for the tool folder. To build and use plug-in registration tool, you must first install Windows the Identity Foundation .
  • The user account must have System Customizer or System Administrator role.

Introducing custom workflow

%TrainingKit%\Labs\WorkflowVS2010\Sources\Assets\WorkflowXamlTool.

Open WorkflowXamlTool.sln, modify workflow name and primaryentity, execution solution.

 

var newWF = new Entity("workflow");

newWF.Attributes.Add("name", "On test 10311");

newWF.Attributes.Add("type", new OptionSetValue(1));

newWF.Attributes.Add("scope", new OptionSetValue(4));

newWF.Attributes.Add("category", new OptionSetValue(0));

newWF.Attributes.Add("primaryentity", "abc_dummy");

newWF.Attributes.Add("xaml", content2);

newWF.Attributes.Add("ondemand", true);

 

try

{

_serviceProxy.Create(newWF);

 

MessageBox.Show("Workflow successfully imported.", "Import", MessageBoxButtons.OK, MessageBoxIcon.Information);

}

catch (FaultException ex)

{

}

选择自定义xaml 文件,导入。

 

 

 

如何更新workflow activity dll

  1. 停止MSCRMAsyncService服务

  2. 执行iisreset – stop
  3. 替换dll 文件到C:\Program Files\Microsoft Dynamics CRM\Server\bin\assembly.
  4. 执行iisreset – start
  5. 开启MSCRMAsyncService服务

     

如何调试workflow activity

Attach 进程CrmAsyncService.exe,执行workflow.

 

 

Workflow activity如何更新数据

IOrganizationServiceFactory serviceFactory = executionContext.GetExtension<IOrganizationServiceFactory>();

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

InfluencerContext context = new InfluencerContext(service);

 

context.ClearChanges();

context.Attach(influencer);

context.UpdateObject(influencer);

context.SaveChanges();

 

Reproduced in: https: //www.cnblogs.com/csswuxi/archive/2012/11/02/2751342.html

Guess you like

Origin blog.csdn.net/weixin_30938149/article/details/94998584