Dynamics CRM 2011: Diving into the sales pipeline – Part 3

In my previous post of this series we discussed how to apply our previously defined sales pipeline through the customisation of the Opportunity entity form. We went through the design of the Opportunity form, which included the addition of fields built-in fields which aren’t part of the default form, and we added some scripts for the calculation of our probability matrix.

Important Update: This article series has been written before the release of Dynamics CRM 2011 Update Rollup 12 (also known as Polaris). You might continue to read the articles in this series, but it is strongly recommended that you read this addendum before performing any customisations suggested in the series.

In this final post we will go through the creation of some workflows that will be part of our sales pipeline process.

Overview of the processes

We are going to create three workflows for the Opportunity entity. One of these workflows, the main one entitled Sales Process, will be triggered with the creation of an opportunity. This workflow is the one which the Sales Pipeline report will use for the sales pipeline phases. The second workflow entitled Sales Process – Post Mortem is a child process, which will be called by the main Sales Process workflow when the opportunity is marked as lost or won. Finally, the third workflow entitled Sales Process – Reopen of Opportunity will be triggered only when an opportunity is reopened (that is, it status changes from closed to open).

So let’s start by adding the first workflow. I assume you’re already logged into Dynamics CRM through an account that has administrative or customisation privileges.

Sales Process workflow

As mentioned in a previous post of this series, the default Sales Pipeline report that comes with Dynamics CRM relies on a workflow of the Opportunity entity to show the different stages of the Sales Pipeline. Therefore we are going to create a workflow for this purpose with the same stages of our sales pipeline as we did to customise the Opportunity form in my previous post.

All that this workflow is going to do is to move through its stages as the sales process progresses so the Sales Pipeline report can make use of it. However, you might as well add your own actions to the stages of this workflow if you wish to do so.

  1. Add a new blank process of the category workflow for the entity Opportunity entitled Sales Process:

    Process name: Sales Process
    Entity: Opportunity
    Category: Workflow
    Type: New blank process

    Click on OK to confirm your settings and load the workflow design window.
  2. Editing workflows: It doesn’t matter what name you give to your workfow and you can also rename and modify workflows at a latter stage if you want. However, in order for a workflow to work it must be activated, and activated workflows can’t be modified. If you wish to modify a workflow at a latter stage, whether to change its name or to modify its actions, you will have to deactivate the workflow.

  3. In the workflow design window under the General tab, make sure you set the process properties as follows:
    Process Name: Sales Process
    Activate As: Process
    Available to Run: As a child process
    Scope: Organization
    Start when: Record is created
  4. Next we will start adding the stages of the workflow. Click on Add Step and select Stage and name the first stage 1 - Prospect. Repeat these steps to add two more stages: 2 - Proposal and 3 - Negotiation.
  5. Workflow steps – Naming stages and describing actions: Dynamics CRM allows you to provide a name/description for every step in your workflow, which are mandatory for the stages of a workflow, but are optional for the sub-steps (i.e.: “actions”) within a stage.

    Remember that the name of the stages will be used by the Sales Pipeline report, so for the sake of consistency they must reflect the same names we defined for the Sales Pipeline in the previous posts of this series.

    However I will not be telling you what descriptions to use for the steps in each stage since this is irrelevant for the workflow to work, but you can refer to the screenshots below as they show the descriptions I have provided for the actions.

    Now under each stage we must add a wait condition with a parallel wait branch. The idea is that the workflow is waiting either for the opportunity to move to the next stage, or for the opportunity to close. If the Process Code field (which is “disguised” as the Pipeline Phase field in the form) changes to the next option, then the workflow will move to the next phase. Otherwise, if the opportunity record is closed as lost or won, then call the Sales Process – Post Mortem workflow to deal with the closed opportunity, and stop the workflow.

  6. Under the first stage (1 – Prospect), select the line that says Select this row and click Add Step. Click on Add Step and select Wait Condition.
  7. Click where it says (click to configure) and set the condition as: Opportunity:Proccess Code equals
    [2 - Proposal].
  8. Repeat the two previous steps (4 and 5) for the second stage. However, make sure that for this stage we are waiting for the condition Opportunity:Process Code equals [3 - Negotiation].
  9. Under the third and last stage will add a wait condition just as we did for the other two previous steps. However this time we want to configure the waiting condition to be Opportunity:Status equals [Lost;Won].
  10. We should now have the steps configured for our workflow as the following screenshot:

    The workflow as it is will move through the stages as the Opportunity’s Process Code field (again, which is “disguised” as Pipeline Phase field in the form) is updated. However, what if the opportunity is closed? For that we must account for other conditions. Our next step will be to create the workflow that will be called by this workflow when the opportunity closes.

  11. For now, click on Save and Close so we can proceed to design our next workflow. We will come back to this workflow afterwards to add the required parallel wait branches.

Sales Process – Post Mortem workflow

This next workflow is pretty straightforward. We are going to create a child workflow which will be called by our main Sales Process workflow when an opportunity is either lost or canceled, and perform given actions accordingly.

  1. Add a new blank process of the category workflow for the Opportunity entity entitled Sales Process - Post Mortem:

    Process name: Sales Process - Post Mortem
    Entity: Opportunity
    Category: Workflow
    Type: New blank process

    Click on OK to confirm your settings and load the workflow design window.
  2. In the workflow design window under the General tab, make sure you set the process properties as follows:
    Process Name: Sales Process - Post Mortem
    Activate As: Process
    Available to Run: As a child process
    Scope: Organization
    Start when: Record is created
  3. Next we will design the workflow as per the screenshot below. Click on Add Step and select Stage and name the stage X - Post Mortem. Note: We are just adding this stage for consistency, since this workflow doesn’t require stages.
  4. Select the line that says Select this row and click Add Step. Click on Add Step and select Check Condition.
  5. Click where it says (click to configure) and set the condition as: Opportunity:Status equals [Lost].
  6. Click on the next line where it says Select this row and click Add Step. Click on Add Step and select Update Record. Make sure that where it says Update the Opportunity entity (the primary entity) is selected, and click on Set Properties. In the form, click on the Probability (%) field and type 0, then click on Save and Close to return to the workflow designer.
  7. Editing read-only fields: If you remember from the previous post in the series, the Probability (%) field has been set as read-only when customising the Opportunity form. We will need to temporarily remove the read-only restriction of the Probability field and re-publish our customisation in order to be able to specify values for this field.

  8. Back at the workflow designer, make sure that the last step we added is selected (the one that updates the Opportunity’s probability) then click on Add Step and select Stop Workflow. Make sure that where it says Stop workflow with status of the option Succeeded is selected.
  9. Now click on the line that says If Opportunity:Status equals [Lost] in order to select the whole condition. Click on Add Step and select Conditional Branch.
  10. At the line that says Otherwise, click where it says (click to configure) and set the condition as: Opportunity:Status equals [Won].
  11. Repeat the same steps as step 6 above. However, this time when setting the properties in the form, type 100 in the Probability (%) field.
  12. Finally, repeat the same steps as step 7 above.
  13. We should now have the steps configured for our workflow as the following screenshot:

  14. Click on Save and Close so we can proceed to update the previous workflow.

Sales Process workflow – revisited

Now we must update our Sales Process workflow so it can trigger the Sales Process – Post Mortem workflow we just created when an opportunity is closed. SO lets proceed to edit the Sales Process workflow.

  1. Under the first stage (1 – Prospect), click on the line that says Wait until in order to select the whole condition. Click on Add Step and select Parallel Wait Branch.
  2. At the line that says Otherwise, click where it says (click to configure) and set the condition as: Opportunity:Status equals [Lost;Won].
  3. Click on the next line where it says Select this row and click Add Step. Click on Add Step and select Start Child Workflow. Make sure that where it says Start child workflow the Opportunity entity (the primary entity) is selected, and then select the Sales Process - Post Mortem workflow in the lookup field.
  4. Make sure that the last step we added is selected (the one that starts the child workflow) then click on Add Step and select Stop Workflow. Make sure that where it says Stop workflow with status of the option Succeeded is selected.
  5. Repeat all previous steps (steps 1-4) for the second stage. Leave the last stage as it is.
  6. We should now have the steps configured for our workflow as the following screenshot:

    The workflow now will move through the stages as the Opportunity’s Process Code field (again, which is “disguised” as Pipeline Phase field in the form) is updated. If the opportunity is closed (either lost or won) the workflow will call the Sales Process – Post Mortem workflow and stop the workflow as successful.

    Actions: You might have noticed that at each stage of our workflow, all that we do is wait we have added no actions to take place. The idea of this workflow is simply to support the Sales Pipeline report and introduce the design of workflows in the process. Feel free to add your own actions to these workflows if you wish to do.

  7. Click on Save and Close so we can proceed to create our last workflow.

Now consider this: The Sales Process workflow follows the life-cycle of an opportunity from the moment it is created. However, what would happen if a user re-opens an opportunity record? At the moment, nothing would happen. But we can create one final workflow to cover this scenario.

Sales Process – Reopen of Opportunity

This final workflow will be triggered when an opportunity status is changed. If the status is changed to open (i.e.: the opportunity is re-opened), then the Sales Process workflow will be called. Otherwise, the workflow will stop as succeeded.

  1. Add a new blank process of the category workflow for the entity Opportunity entitled Sales Process – Reopen of Opportunity:

    Process name: Sales Process - Reopen of Opportunity
    Entity: Opportunity
    Category: Workflow
    Type: New blank process

    Click on OK to confirm your settings and load the workflow design window.
  2. In the workflow design window under the General tab, make sure you set the process properties as follows:
    Process Name: Sales Process - Reopen of Opportunity
    Activate As: Process
    Available to Run: no option selected
    Scope: Organization
    Start when: Record status changes
  3. Click on Add Step and select Check Condition.
  4. Click where it says (click to configure) and set the condition as: Opportunity:Status equals [Open].
  5. Click on the next line where it says Select this row and click Add Step. Click on Add Step and select Update Record. Make sure that where it says Update the Opportunity entity (the primary entity) is selected, and click on Set Properties. In the form, click on the Probability (%) field and type 5, for the Rating field select Cold and for the Process Code field select 1 - Prospect then click on Save and Close to return to the workflow designer.
  6. Back at the workflow designer, make sure that the last step we added is selected (the one that updates the opportunity’s probability, rating and process code) then click on Add Step and select Start Child Workflow. Make sure that where it says Start child workflow the Opportunity entity (the primary entity) is selected, and then select the Sales Process workflow in the lookup field.
  7. Make sure that the last step we added is selected (the one that starts the child workflow) then click on Add Step and select Stop Workflow. Make sure that where it says Stop workflow with status of the option Succeeded is selected.
  8. Now click on the line that says If Opportunity:Status equals [Open] in order to select the whole condition. Click on Add Step and select Default Action.
  9. Under Otherwise select the line that says Select this row and click Add Step. Click on Add Step and select Stop Workflow. Make sure that where it says Stop workflow with status of the option Succeeded is selected.
  10. We should now have the steps configured for our workflow as the following screenshot:

  11. Click on Save and Close so we can proceed to activate our workflows.

Activating and testing the workflows

After saving and publishing our workflows, our next step is to activate our workflows so we can test them.

  1. After activating the workflows, proceed to create an opportunity and save it without closing it.
  2. If you click on Workflows under Procecces at the left-hand side navigation pane in the Opportunity form, you will be able to see the associated Sales Process workflow which has been triggered upon the creation of this Opportunity record.
  3. Go back to the General tab of the Opportunity form and change the Pipeline Phase from 1 - Prospect to 2 - Proposal. Now if you go back to the associated workflow view (see previous step) and click on the Sales Process workflow, you can see its progress.
  4. Workflow stages: Unfortunately Dynamics CRM 2011 workflow designer only allow a linear and sequential progression through the stages of a workflow. In practical terms, this means that from Stage 1 we can only progress to Stage 2, from Stage 2 to Stage 3 and so forth; and we can’t jump a stage or go backwards on stages. This is why we added the bonus JScript in the previous post of the series to enforce users to follow a linear and sequential progression. If you want to create a workflow that allow jumping back and forth through its stages, you will have do design the workflow using Visual Studio.
    Update May/2012: Even though the Dynamics CRM 2011 workflow designer doesn’t allow us to jump stages (e.g.: like a “GOTO” statement), we could still progress through all the stages if a user jumps forward by adding additional conditionals, and even support users moving backwards through additional parallel wait branches and restarting the Sales Pipeline workflow as a child workflow from itself. Because this would significantly increase the complexity of this workflow, I decided to cover this scenario in subsequent post.

  5. Now proceed to view all of the open opportunities. At the Ribbon, click on Run Report and select the Sales Pipeline report. When prompted to select records, select All applicable records then click on Run Report.
  6. When the report finish to load, at the top where it says Group by Sales Process select Sales Process (the name of our workflow) from the drop-down. Where it says Group By select Sales Stage. Then click on View Report to update the report. We should now see the opportunities estimated revenue grouped by the sale stages.
  7. The report takes the sale stages from the stages of our Sales Process workflow. You might be wondering why couldn’t this report make use of the same field as the pipeline chart does in the previous post of this series. I asked myself the same question when I first came across this report. However it does make sense to have the report based on the workflow stages and the chart on an entity field; particularly if you have complex workflows and sub-stages for dealing with different products or business units.

Wrapping up

Wow… That was a lot of writing. Through the course of this series we introduced a lot of concepts for creating a functional sales pipeline in Dynamics CRM 2011. Through the customization of the Opportunity entity we also introduced some useful JScripts which calculate fields and remove options from option sets. Also through the design of workflows we introduced the concepts of conditionals, waits and branches; as well the use of child workflows. I hope you enjoyed this series and that it can be a useful reference for those in the Dynamics CRM community. Thank you for stopping by!

Bonus: Challenge yourself

Update Jan/2012: Because the sales pipeline is only about open opportunities, we only covered the open stages of the opportunity in this series of posts (1 – Prospect, 2 – Proposal, 3 – Negotiation). However, let’s say that for consistency we would also like the Pipeline Phase field of a closed opportunity to show either “4 – Won” or “X – Lost”, in case someone opens the form of a closed opportunity record. How could we do that?

This can easily be done with by adapting our workflow to change the value of the Pipeline Phase (stepname) accordingly for when an opportunity is closed either as won or as lost. As for our Process Code (salesstagecode) field labeled as Pipeline Phase, we can either adapt our JScript to hide it when a form is disabled (using CRM_FORM_TYPE == 4) so users would only see the Pipeline Phase (stepname) in the form footer when viewing inactive records. Alternatively, we can add two additional options to the Process Code (salesstagecode) and have them always hidden from the end-user in an editable form by adapting the bonus JScript proposed in the previous post. Then the workflow would update the value of the Process Code option set according to the close status of the opportunity (either as won or as lost).

Have fun!

Tags: , , ,

13 Comments

Blog Categories

Recent Posts