How to use the Logical User fields in Microsoft Dynamics CRM 3.0 workflow rules

This article has been archived. It is offered "as is" and will no longer be updated.
When you use workflow rules in Microsoft Dynamics CRM 3.0, you can send e-mail messages to the following Logical User fields:
  • account
  • contact
  • account/contact
  • owner
  • owner’s manager
The corresponding information for the fields that you select populates the e-mail message that is created. This information relates to the record that triggers the workflow rule.

For example, consider the following scenario:
  • You create a workflow rule that is triggered when you create a case in Microsoft Dynamics CRM 3.0.
  • You send e-mail messages to the "contact" Logical User dynamic field in the workflow rule.
  • You send e-mail messages to the "owner’s manager" Logical User dynamic field in the workflow rule.
  • A case is created.
  • An e-mail message is sent to the contact that is listed as the customer in the case. The message is also sent to the manager for the owner of the case.
More information
In some scenarios, you may want to use the Microsoft Dynamics CRM 3.0 SDK to create Workflow .NET assemblies.

For example, if you create the scenario that is mentioned in the "Introduction" section in which the customer is an account and the owner of the case does not have a manager, the workflow rule pauses in Workflow Monitor and generates an error. If you use a template to create the e-mail message in the workflow rule, the e-mail message is created but the message is not sent. Additionally, the From, the To, the CC, and the BCC fields in the e-mail message are not populated.

To work around this behavior, use the Microsoft Dynamics CRM 3.0 SDK and the Check Entity Conditions condition. Alternatively, you can use the "account/contact" Logical User dynamic field.
Note The "account/contact" Logical User dynamic field works whether the customer is an account or is a contact.

Use the Microsoft Dynamics CRM 3.0 SDK to create workflow .NET assemblies

Use the Microsoft Dynamics CRM 3.0 SDK to create workflow .NET assemblies to prevent errors or to prevent e-mail messages that are addressed incorrectly.

For example, you can create an assembly that can determine whether the owner of the record has a manager. To do this, use the CRMService Web service for Microsoft Dynamics CRM 3.0.

To create a workflow .NET assembly, follow these steps:
  1. Use the Check Entity Conditions condition to determine whether the customer who is listed on the case is an account or is a contact.

    To determine whether the customer is an account, verify that a required field on the account record is populated. For example, verify that the Account Name field is populated. To determine whether the customer is a contact, verify that the Full Name field is populated. After the rule has determined which field is populated, the rule can create an e-mail activity that is logically addressed either to an account or to a contact.

    Use the following sample code to determine whether the owner of a record has a manager.

    Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.
    using System;using System.Collections.Generic;using System.Text;using System.Xml.Serialization;using System.Xml;using System.IO;using CheckLogicalItems.crmsvr;namespace CheckLogicalItems{    public class LogicalItems    {                 /// <summary>        /// Checks for a manager on the given user guid        /// </summary>        /// <param name="user">Owner of the record workflow is processing against</param>        /// <returns>true if user has a manager, false if user does not have a manager</returns>        public bool CheckForManager(Guid user)        {// Create the CRM Service Object.CrmService cService = new CrmService();	// Create the ColumnSet Object.ColumnSet columnSet = new ColumnSet();	// Determine your identity.WhoAmIRequest whoAmI = new WhoAmIRequest();	WhoAmIReponse Iam = (WhoAmIResponse)cService.Execute(whoAmI);	// Set the credentials for the service.cService.Credentials = System.Net.CredentialCache.DefaultCredentials;	cService.CallerIdValue = new CallerId();	cService.CallerIdValue.CallerGuid = Iam.UserId;            // Set the attributes to be returned.columnSet.Attributes = new string[] { "parentsystemuserid" };            // Request the parentsystemuserid field for the record owner.systemuser owner = (systemuser)cService.Retrieve(EntityName.systemuser.ToString(), user, columnSet);            // Determine whether the record owner has a manager listed in Microsoft CRM.// Return "false" if the field is null.// Return "true" if the field has a value (the owner has a manager).if(owner.parentsystemuserid == null)               return false;            else                return true;        }     }}
  2. Update the Workflow.config file. Sample code for the Workflow.config file is located in the following folder:
    C:\Program Files\Microsoft CRM\Server\bin\assembly\
    If the assembly is unsigned, you must add the allowunsignedassemblies attribute to the <workflow.config> element at the top of the Workflow.config file. Assign a value of "true" to the allowunsignedassemblies attribute. To update the Workflow.config file, use the following code sample.
    <workflow.config xmlns=      allowunsignedassemblies="true"><methods>…<method name="Check for Manager"       	assembly="CheckLogicalItems.dll"       	typename="CheckLogicalItems.LogicalItems"       	methodname="CheckForManager"       	group="Check Logical Item Conditions" description="Checks for a manager for the record owner">      <parameter name="Owner" datatype="lookup" entityname="systemuser"/>      	<result datatype="boolean"/></method>…</methods></workflow.config>
  3. After you build the assembly, copy the .dll file to the following directory:
    C:\Program Files\Microsoft CRM\Server\bin\assembly\

Use workflow .NET assemblies and the Check For Manager action

To use workflow .NET assemblies and the Check For Manager action, follow these steps:
  1. Restart the Workflow service.
  2. Start Workflow Manager. To do this, click Start, point to All Programs, point to Microsoft CRM, and then click Workflow Manager.
  3. Click the rule that you want to modify, click Actions, and then click Open.
  4. Click Insert Action, point to Call Assembly, point to Check Logical Item Conditions, and then click Check For Manager.
  5. Double-click the Owner parameter, click Dynamic Value, and then click OK.
  6. In the Action Name box, type a name for the action, and then click OK.
After you make these changes, you can use the result from the Check For Manager action to determine your next step. Base your decision on whether the owner of the record has a manager. For example, you can send an e-mail message to the "owner's manager" Logical User dynamic field.

Article ID: 922607 - Last Review: 01/15/2015 09:06:01 - Revision: 2.0

  • kbnosurvey kbarchive kbmbscrm40no kbmbsworkflow kbmbsmigrate kbhowto KB922607