Eric's Blog

有需求才有进步

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

In this example we are going to create a .NET assembly and then call that .NET assembly from the MSCRM workflow engine. This new ability to call .NET Assemblies can have important benefits for our customers.

This example is going to create a very simple .NET assembly class to demonstrate the concept. The method will take a string as an input and return that string converted to upper-case letters.

So fire up VS 2005 and select File->New->Project, and select Visual C#->Windows->Class Library

After VS creates the project you should have something similar to this:

Create a new method in the class called retStr as shown below, be sure to include the required "using" statements as well.

Build your assembly file and then copy the file to the following directory on your MSCRM server:

<Installation drive\Program Files\Microsoft CRM\Server\bin\assembly

Remember to Sign the Assembly

Next you need to stop the MSCRM workflow service on the MSCRM server. Click Start->Administrative Tools->Services and find the MSCRM Workflow service as shown:

Double-click the row to bring up the properties for the service, and then click the "Stop" button.

Make sure the Service Status reads "Stopped" before proceeding to the next step.

We next need to add the XML for our new Assembly and method to the workflow.config file. Adding the XML to this file is what will enable us to access the assembly from Workflow.

This file will be in the same directory we copied the Assembly to earlier,

<Installation drive\Program Files\Microsoft CRM\Server\bin\assembly

Add the following XML to the file just before the </methods> closing tag:

<method name="ConvertToUpper"
assembly="ClassLibrary1.dll"
typename="ClassLibrary1.Class1"
methodname="retStr"
timeout="7200">
<
parameter name="inputString" datatype="string" default=""/>
<
result datatype="string"/>
</
method
>

Parameters:
name: This can be anything you want it to be
assembly: must match the name of the DLL you build
typename: this must be the fully-qualified name of your class. So since we created our code thus:

namespace ClassLIbrary1
{
  public class Class1
  {
  }
}
the typename in this case is ClassLibrary1.Class1
methodname: the name of the method in our assembly
timeout: an optional parameter that defines the timeout value for the call.

The "<parameter name" tag is for any input parameters to the method, in this case we need 1 input parameter of string type
The "result datatype" tag defines the type returned by the method, in this case it is a string.

Save and close the file.

Next we need to restart IIS, so click Start->Run and type "iisreset"

Finally we need to restart the Workflow service, so back at the Workflow service properties window click the "Start" button, before proceeding to the next step make sure the "Service Status" label now reads "Started"

Ok, now we can use our assembly from Workflow!

On the MSCRM Server, click Start->All Programs->Microsoft CRM->Workflow Manager

In Workflow Manager, Select "Lead" for "Entity Type" and Select "Rule" for "View", then click File->New

Call the rule "AssemblyTest", select "Manual" from the :"Event" dropdown, and click "Next>"

Click Insert Action->Call Assembly->ConvertToUpper

In "Action Name" type "retStr" and then double-click on the "inputString" row. In the box that appears, choose "Dynamic Value", leave "Lead" as the entity, and then from the "Field" drop-down choose Company Name:

Click OK, and then OK again to return to the Workflow screen. The screen should now look like this:

Next click "Insert Condition->Check conditions"

. Click <<add conditions here>>, click Insert Condition, and then click Check entity condition.

On the next screen select our method name, retStr from the "Entity" drop-down,  and select "not null" from the middle drop-down, and click "OK".

The workflow manager window should now look like this:

Click the remaining <<add actions here>>, click Insert Action, and then click Update entity.

In the Update Entity window, the Entity should be set to Lead, the Field to CompanyName, the operator to =, and then click the lookup (hte icon that looks like a magnifying glass):

In the Select Value window, select the "Dynamic Value" selection, and then click set the Entity to "retStr". Click OK, and then OK again on the next screen, twice and you should be back to the main workflow window.

The workflow window should now look like this:

Click Save. Now back in the main workflow manager window, select your new rule and then click "Activate"

Make sure the Status changes to "Active" and you are ready to test.

Open up MSCRM and click Sales->Leads. Click a Lead that has data in the Company Name Field, and select More Actions->Apply Rule

You should see the screen below, click "OK"

Open the Lead you applied the rule to and the Company Name should be in all capital letters:

And that's it!

So, while converting the company name to all capital letters does not really accomplish any mission-critical processing, this lab ahs shown the basics in creating an assembly and then accessing that assembly from Microsoft Dynamics CRM v3.0 Workflow. Thanks to Jon and Kristen from Fargo for their help! :)

posted on 2008-03-31 13:39  Eric.Chai  阅读(241)  评论(0编辑  收藏  举报