Microsoft KB Archive/922607

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

Article ID: 922607

Article Last Modified on 9/1/2006

-

APPLIES TO


 * Microsoft Dynamics CRM 3.0
 * Microsoft CRM 3.0 Software Development Kit

-



INTRODUCTION
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 &quot;contact&quot; Logical User dynamic field in the workflow rule.
 * You send e-mail messages to the &quot;owner’s manager&quot; 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 &quot;Introduction&quot; 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 &quot;account/contact&quot; Logical User dynamic field.

Note The &quot;account/contact&quot; 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:   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 {                ///         /// Checks for a manager on the given user guid ///        /// Owner of the record workflow is processing against /// true if user has a manager, false if user does not have a manager 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[] { &quot;parentsystemuserid&quot; }; // 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 &quot;false&quot; if the field is null. // Return &quot;true&quot; if the field has a value (the owner has a manager). if(owner.parentsystemuserid == null) return false; else return true; }    } }   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  element at the top of the Workflow.config file. Assign a value of &quot;true&quot; to the allowunsignedassemblies attribute. To update the Workflow.config file, use the following code sample.  …    …   After you build the assembly, copy the .dll file to the following directory:

C:\Program Files\Microsoft CRM\Server\bin\assembly\

</ol>

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 &quot;owner's manager&quot; Logical User dynamic field.

Keywords: kbhowto kbmbsmigrate kbmbsworkflow KB922607

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.