The Microsoft Dynamics CRM Blog
News and views from the Microsoft Dynamics CRM Team

Extending CRM Workflow with Echo functions

Extending CRM Workflow with Echo functions

  • Comments 6

Scenarios:

Echo functions are .NET assemblies that can be registered with CRM workflow service. Echo functions enable the user to declare some temporary variable inside a workflow definition. These temporary variables, then can be used to compare attribute values at certain time intervals (e.g. à between updates or every two hours). Some of the scenarios enabled by this capability are as follows:

  • Kevin is a Sales Manager. He wants to ensure that he is notified via an e-mail each time a salesperson pushes the opportunity estimated close date into future.
  • Nancy is Salesperson. She would like to log all changes that are made to the rating of a lead for future reference (e.g. à from warm to hot or warm to cold).
  • Charlie is the CEO. He would like to know if the estimated opportunity revenue is changed by more than $50,000 anytime on any opportunity.

Approach:

  • Create .NET assemblies with methods that return values with specific data types.
  • Register these .NET assemblies and associated methods with “workflow.config” file.
  • Use the registered methods to declare temporary variables inside a workflow definition in order to enable specific scenarios.

Steps:

1.      Create Echo functions for each crm data type:

      public string EchoString( string value )

      {

            if( value == null )

                  throw new Exception( "null string" );

 

            return value;

      }

 

      public int EchoInteger( int value )

      {

            return value;

      }

 

      public DateTime EchoDateTime( DateTime value )

      {

            return value;

      }

 

      public double EchoDecimal( double value )

      {

            return value;

      }

 

      public bool EchoBoolean( bool value )

      {

            return value;

      }

 

      public string EchoCaller( string value )

      {

            return value;

      }

 

      public Guid EchoLookup( Guid value )

      {

            return value;

      }

 

      public int EchoPicklist( int value )

      {

            return value;

      }

 

2.      Next compile these methods into an assembly and place it in the <Crminstalldir>\ MSCRM\Server\bin\assembly

3.      Register the methods in the workflow.config file.

 

            <method name="EchoString" assembly="workflowtestassembly.dll" typename="HelloType" methodname="EchoString" group="Echo">

                  <parameter name="Value" datatype="string"/>

                  <result datatype="string"/>

            </method>

            <method name="EchoInteger" assembly="workflowtestassembly.dll" typename="HelloType" methodname="EchoInteger" group="Echo">

                  <parameter name="Value" datatype="integer"/>

                  <result datatype="integer"/>

            </method>

            <method name="EchoDecimal" assembly="workflowtestassembly.dll" typename="HelloType" methodname="EchoDecimal" group="Echo">

                  <parameter name="Value" datatype="decimal"/>

                  <result datatype="decimal"/>

            </method>

            <method name="EchoBoolean" assembly="workflowtestassembly.dll" typename="HelloType" methodname="EchoBoolean" group="Echo">

                  <parameter name="Value" datatype="boolean"/>

                  <result datatype="boolean"/>

            </method>

            <method name="EchoCaller" assembly="workflowtestassembly.dll" typename="HelloType" methodname="EchoCaller" group="Echo">

                  <parameter name="Value" datatype="caller"/>

                  <result datatype="string"/>

            </method>

            <method name="EchoLookup" assembly="workflowtestassembly.dll" typename="HelloType" methodname="EchoLookup" group="Echo">

                  <parameter name="Value" datatype="lookup" entityname="account"/>

                  <result datatype="lookup" entityname="account"/>

            </method>

            <method name="EchoPicklist" assembly="workflowtestassembly.dll" typename="HelloType" methodname="EchoPicklist" group="Echo">

                  <parameter name="Value" datatype="picklist" entityname="account" attribute="accountcategorycode"/>

                  <result datatype="picklist" entityname="account"  attribute="accountcategorycode"/>

            </method>

            <method name="EchoDateTime" assembly="workflowtestassembly.dll" typename="HelloType" methodname="EchoDateTime" group="Echo">

                  <parameter name="Value" datatype="datetime"/>

                  <result datatype="datetime"/>

            </method>

            <method name="EchoXml" assembly="workflowtestassembly.dll" typename="HelloType" methodname="EchoXml" group="Echo">

                  <parameter name="name" datatype="string"/>

                  <parameter name="age" datatype="integer"/>

                  <result datatype="xml">

                        <retval name="name" xpath="//name/text()" datatype="string"/>

                        <retval name="age" xpath="//age/text()" datatype="integer"/>

                  </result>

            </method>

 

Note: That for lookup and picklist you will have to register specifically for the entity or picklist attribute that you would like to use the variable for. I know its wiered but hey its only the xml file, you can reuse the code behind.

 

 

All the above will allow you to capture only one attribute at a time. but if you need to capture multiple variable at a time you can create an Echoxml funtion some thing like.

 

      public string EchoXml( string name, int age )

      {

            return "<user>" +

                  "<name>" + name + "</name>" +

                  "<age>" + age + "</age>" +

                  "</user>";

      }

 

4.      Restart your workflow service and workflow manager. If you had any error in the config file you will see the error logged in the event viewer.

5.      You are all set to use these as custom assembly calls as variables in your workflow rule.

For examples on using these functions, you can see the blog “Tapping into updates via workflow” coming tomorrow.

NOTE à

  • It is recommended that you test the workflow rules in a test environment before you put it in production.
 - Shashi Ranjan
  • Shashi, can you please direct me to the blog "Tapping into updates via workflow"? I can't seem to find it.
  • Coming tomorrow, Nathan.  Sorry. I've corrected the post.
  • Scenario:
    Nancy is Salesperson. She would like to log all changes that are made to the rating of a lead...
  • How will you handle if DateTime has null value?
  • if you use datetime field that is null in a condition then that is going pause the rule with an exception. The best way is to check if the value is null or not using an if condition and when its null pass in a static value for the date time.
  • hi

Page 1 of 1 (6 items)
Leave a Comment
  • Please add 7 and 3 and type the answer here:
  • Post