The Dialog feature does not provide loop structure so you cannot do the same action or set of actions in a loop however there is a way to form a virtual loop for performing a set of actions. The way is to use a controlled recursive child Dialog having the desired set of actions being called from a parent Dialog. Here is the trick to do that.
The following hypothetical example will show you how to make Dialog calls recursive. Let us assume that we want to create a Dialog for Customer Service Executive who is creating a Case for her customer. What if she wants to create multiple cases in one call while not starting Dialog again and again and asking the similar set of questions for creating a Case. Here is the step by step method to achieve this. Once acquainted with the trick you can use the recursion for many other scenarios. One such scenario can be creating multiple Contract Lines for a Contract using Dialog Process in Microsoft Dynamics CRM 2011.
1. Create a child Dialog named “create case” for Account entity which ask the relevant things required to create a case. In the example below only Case’s Title is asked in prompt. You can ask for other attributes too by adding as many Add Prompt and Responses steps.
2. Now activate the Dialog and then deactivate without any change. Doing this will make your child Dialog available to be added as its own child, means now recursion is possible for the Dialogs.
3. To control the flow from entering into the infinite loop you can add a Prompt to ask if the customer wants to create another Case. If customer’s choice is yes then add a Link Child Dialog step. In the child Dialog lookup, you would be able to see the same “create case” dialog on which you are currently working. Select this as a child of its own and you got the way to make recursive call to Child Dialogs.
4. Add exit method to get out of recursion using Default Action step thorugh a Page showing Thanks to Customer for registering the Case. The final Dialog will look like below figure
5. Now you are ready to use this recursive Dialog from another Parent Dialog, but before that do not forget to activate this just created Child Dialog. The parent Dialog will look something like below figure.
So you have created a recursive Dialog. Let us test it by running it. Go to Account grid and run this Dialog for any Account record by clicking Start Dialg ribbon button in context to any Account record.
When you run the Dialog, the answer choice on page above of run Dialog will determine whether to recurs or exit.
In above example we saw the way to create recursion and way to exit from recursive loop. Hope this will help you to explore the power of recursive Dialogs in many ways to solve your practical scenarios.
Cheers