Building Business Processes in Dynamics CRM 2011: Installment 9

0
155

Share on LinkedIn

Variables are used for temporary data storage during the lifetime of a dialog. One of the most common reasons to use variables is to calculate a value based on other values. Here are a couple of examples where variables might be required:

  • When a lead is converted to an opportunity, a sales representative might be prompted with several questions about the revenue potential, how supportive is the sponsor, what is the decision timeframe and so forth. Depending on the responses, an Opportunity Score variable could be calculated and used to update a custom field on the opportunity record.
  • A satisfaction survey or a post-even evaluation could be implemented with a dialog process. Individual survey responses could be captured in fields in a custom entity, but you might want to calculate aggregate values (totals, or averages, say) as well. You could use variables to hold these calculated values.

You can create a new variable by clicking on the Add hyperlink in the Variables section of the process designer:

As you can see in the following figure, variables have Name, Data Type, and Default Value properties:

Notice in the previous figure that, just as when you specify the data type of the response in a prompt/response pair, the data type cannot be changed after saving. Some other important features to keep in mind:

You can see one of the differences between the Whole Number and Floating Point data types by comparing the Default Value field in the following two figures:

Example: Using Variables to Score Opportunity Records

Let’s walk through the Score Opportunity dialog process example in detail. It’s written for the Opportunity entity, and as in the previous example, is available to run both As an on-demand process and As a child process. The following figure shows Properties section, the Variables section expanded so you can see the OpportunityScore variable, and the three main stages of the dialog collapsed so you can see everything at once:

I’ll drill down on each of the stages in succession.

  • Stage 1: Prompt and Collect Responses

    The following figure shows stage 1 expanded:

    Stage 1 contains the single page of this dialog process, which exposes the prompt/response pairs. In the previous figure, the Decision Timeframe Prompt and Response is highlighted; clicking Set Properties opens the following Define Prompt and Response dialog:

    The most important things to notice here are:

    • Notice the Data Type is set to Integer. We discussed this previously, but I want to emphasize the importance of getting this right the first time in. Text is the default, and I can’t tell you how many times I’ve forgotten to change it in situations when I really need the Integer value. It can take a while to specify the several response values for an option set…and if you get the data type wrong the only way to fix it is to delete and start over!
    • Next, notice that the 3-6 months Response Value is selected, and the values of the associated Value and Label properties. These really define the business rules behind the specific opportunity scoring algorithm being designed, and will of course vary from one organization to another (not to mention the questions!). But to give you a feel for how this can work, the following table lists the values for each of the four possible responses for the Decision Timeframe prompt, along with my thought process for the values:

    Response Label Response Value Thought Process
    Less than 3 months 0 Too quick; an indication we’re coming in late and may be proposal fodder
    3-6 months 10 The sweet spot.
    6+ months 5 More than 6 months might be a little better than less, but it’s not as good as

    3-6.

    Don’t know/won’t say -5 Either we haven’t done our homework to find out, or the customer won’t tell us.

    Either way it’s bad, so we deduct points from the score.

    Stage 2: Calculate OpportunityScore Variable using Assign Value

    In stage 2, we use Assign Value to successively increment the OpportunityScore variable. You can see this in the following figure, which shows stage two expanded with the Increment by Timeframe score step highlighted:

    Clicking on Set Properties for that step shows the following Assign Value dialog:

    This ties back to the point I made in describing stage 1, about the importance of the Integer data value in this case. The value of the OpportunityScore variable is incremented here by the Response Value of the Decision Timeframe response. If I’d forgotten to specify Integer as the data type, the Response Value drop-down in the Dynamic Values section would be depressingly empty, reminding me too late that (once again!) I went too fast in the Prompt and Response dialog and got the wrong data type.

    Another thing to watch out for here is the option selected for the Operator. For a cumulative score like the one calculated in this process, Increment By is the way to go. The first time I wrote a scoring dialog process like this one, I accidentally selected Set to on the very last Assign Value step in the stage. When testing it, I kept wondering why no matter how good or bad I scored all the rest of the questions, the overall score never got much above or below zero. Don’t let that happen to you!

    For numeric fields, the operators you can use Set to, Increment by, Decrement by, Multiply by, and Clear. (No Divide by. Bummer!) You can see them all here:

  • Stage 3: Update Custom Field on Opportunity with OpportunityScore Variable

    Stage 3 is the easiest to understand, since all it does is use the calculated value of the OpportunityScore variable to update the opportunity record:

    Click Set Properties to open the Update Opportunity dialog. The following figure shows how I update it in this example:

    In this example, I added a custom field, Opportunity Score, to the opportunity entity. I defined it as a Whole Number data type. This is important because it corresponds to the data type for the OpportunityScore variable in the dialog, which here is used to update the field value on the record.

    Notice that Dialog is selected in the Look for drop-down. This is a special value that is used specifically to expose variables in dynamic values for dialog processes. You can verify this the next time you’re in the dialog designer working on a dialog without any variables defined, in which case Dialog will not appear in the Look for drop-down.

    Here’s what it looks like when it’s there:

  • How it Works

    Let’s take a look at the user experience for the Score Opportunity dialog process. First, remember that it’s written for the opportunity record type and it’s available to run as an on-demand process. This means it can be run by clicking Start Dialog with an opportunity record selected on the data grid, or from the ribbon on the opportunity form.

    From the data grid:

    Of from the form:

    After selecting Score Opportunity and kicking it off, here’s what the dialog process looks like:

    This dialog has a single page only, so after clicking Next and then Finish, the dialog gathers the responses, uses them to update the OpportunityScore variable, which in turn is used to update the opportunity record.

    Here are a couple of observations on some of the business issues a process like this might raise:

    • Notice that the implementation details of a process like this one impose some business rules. In this example, they mean that an opportunity can be scored more than once. This may be appropriate for some organizations, but you can also imagine imposing a “score once only” rule. Suppose instead of creating the dialog process for the opportunity record type and making it available for on-demand use, you only exposed it for use as a child process, and called it from a custom lead conversion process. This would effectively enforce the score once only rule…especially if you remember to take the Opportunity Score field off the opportunity form!
    • The way I wrote this dialog process, the OpportunityScore field ranges from a maximum value of 50 to a minimum of -50. While there’s nothing particularly scientific about the approach I used, I’ve known sales managers who claim to have a fool-proof lead qualification process consisting of a small number of simple questions a relatively inexperienced sales rep can ask a potential customer. If you’re in that category, here’s your chance to bake it into your CRM!

Republished with author's permission from original post.

Richard Knudson
Richard Knudson is a Dynamics CRM consultant and instructor, and has a special interest in cloud computing and helping organizations realize the potential of social CRM. His company, IMG, specializes in helping businesses implement and customize the Dynamics CRM platform.

ADD YOUR COMMENT

Please use comments to add value to the discussion. Maximum one link to an educational blog post or article. We will NOT PUBLISH brief comments like "good post," comments that mainly promote links, or comments with links to companies, products, or services.

Please enter your comment!
Please enter your name here