Overview
Sometimes business processes are more complicated and have significant permutations that are not easily managed with out-of-the-box Business Process Flow (BPF) functionality. In this article we will demonstrate how you can use North52 Decision Tables to create rule dependent task checklists for each BPF stage on the Case entities Business Process Flow (BPF) called Phone to Case.
The tasks are created at each BPF stage change and checked to ensure any predecessor tasks are completed first and all tasks for a given stage must completed before the user can move to the next stage.
North52 Decision Suite
The North52 Decision Suite solution works like this:
- A Save - Perform Action Formula is set up on the Phone to Case Process entity which:
- Executes a Decision Table when the Active Stage field changes
- Depending on the selected Stage, Task records are created and associated with the Case
- Executes a Decision Table when the Active Stage field changes
- A Validation Formula on the Phone to Case Process entity checks for open Tasks associated with the Case and the current BPF stage
- If there are open Tasks a Business Process Error is shown to the end-user
- A Save - Perform Action Formula on the Task entity which:
- Checks if the Task has predecessor and if the preceding Task is not Completed
- If the predecessor Task is not Completed then a Business Process Error is shown to the end-user
- Changes the Status
- Checks if the Task has predecessor and if the preceding Task is not Completed
- A Client-Side Formula on the Case entity refreshes the Checklist subgrid when the BPF stage changes
Set up Task Entity, Case Entity and Formulas
Task Entity
We need to add new fields and create a new view on the Task entity.
New Fields
- Create a Decimal field named Sort Order
- Create a Single Line of Text field named BPF Stage
- Create a Lookup field named Predecessor with a Target Record Type of Task
- Create an Option Set field named Change Status (this is used to change the Status Reason via a Formula as the out of the box Status Reason cannot be edited in a Editable Grid) and add the following options:
- Open (set this as the Default Value)
- In Progress
- Completed
- Publish changes
Note: you could add these fields to the Task form too, however the fields are not designed for user input on the form so it is not necessary
New View
- Create a new view called Checklist Items
- Add the Subject (300px), Change Status (125px), and Sort Order columns
- Configure the sort order so that the Sort Order column is selected in Ascending Order
- Publish changes
- We don't really want the Sort Order column displayed, however we want the sort to remain so we can use the View Designer XrmToolBox plugin to modify the view:
Case Entity
We need to add a subgrid showing the Checklist Items view from the previous step on the Case Entity form:
- Open a Case form (we saved a copy of the main Case form and renamed it Case - Checklist Items)
- Insert a new One Column Section and position it at the top of the middle column
- Label the section Checklist and check the option to show the label
- Add a Sub-Grid to the Checklist section
- Set the Name to TaskChecklist
- Set the Label to Task Checklist
- Under the Data Source section set:
- Records = Only Related Records
- Entity = Tasks (Regarding)
- Default View = Checklist Items
- Uncheck Display Chart Selection
- On the Formatting tab, set the Number of Rows to 10
- On the Controls tab add the Editable Grid control
- Disable the Group by Column
- Click OK
- Save and Publish the form
Formula - Create Checklist Task Items
This Decision Table formula will provide the logic which creates the Tasks at each stage of the BPF.
- Create a new formula, setting the following values in the Formula Guide:
- Source Entity set to Phone to Case Process
- Set Formula Type to Save - Perform Action
- Select the Decision Table editor
- Change the Name of the formula to Phone to Case Process - Save - Create Checklist Items
- Set Event to Create & Update
- Expand Source & Target
- For Source Property select Active Stage
- Click Save
Set up Conditions
- Select cell A2
- Select the Source tab
- Expand Related (N:1)
- Expand processstage (activestageid)
- Expand (Attributes)
- Select Process Stage Name
- Select cell A4
- Enter the text 'Identify' including the quotes (this is the Stage Name and can be found by opening the BPF in the BPF editor)
- Select cell B2
- Right-click and select Insert > Insert Condition
- From the Source tab
- Expand Related (N:1)
- Expand incident (incidentid)
- Expand (Attributes)
- Select Case Type {Value}
- Select cell B4
- Expand Case Type {Value}
- Select Problem
- Click Save
Set up Actions (create Task records)
- Right-click anywhere on the Decision Table and select Set Sheet Options > Use Create Record
- Right-click again and select Hit Policy then uncheck Exit this Decision Table on First Match (this means all rows in the Decision Table will be processed even if a condition match occurs on a previous row)
- Highlight colums D to G, right-click and select Insert > Insert Action
- Select the Explore tab
- Enter task in the Search data model input box and press enter
- Expand Task
- Select cell C2
- Select Subject from the Task attributes
- Select cell C4
- Enter the text 'Validate the problem'
- Select cell D2
- Select Sort Order from the Task attributes
- Select cell C4
- Enter the number 1
- Select cell E2
- Select BPF Stage from the Task attributes
- Select cell E4
- Enter the text 'Identify'
- Select cell F2
- Select Predecessor (Value) from the Task attributes
- Select cell G2
- Select Regarding (Value) from the Task attributes
- Select cell G4
- Enter the text 'incident|' + followed by a space
- With the cursor still in cell G4:
- Select the Source tab
- Expand the Source node
- Select Incident (Value)
- Cell G4 should now contain 'incident|' + {Incident (Value)}
- Click Save
- Complete the rest of the Decision Table so that it looks like the image below
- To specify a Predecessor, go the the Source tab
- Expand Decision Table Calculations
- Select the Row number referencing the Task you want as the predecessor (if not all rows showing then click the refresh button at the top right of the Source tab)
- To specify a Predecessor, go the the Source tab
- Click Save
At this point you can test that Tasks are being created at each Stage by creating a Case and progressing through the Stages. We'll add validation formulas in the next sections.
Formula - Validate Tasks are Completed
This Decision Table formula will check that all Tasks associated to the Case and current stage have been completed before progressing to the next stage.
- Create a new formula, setting the following values in the Formula Guide:
- Source Entity set to Phone to Case Process
- Set Formula Type to Validation
- Select the Decision Table editor
- Change the Name of the formula to Phone to Case Process - Validate Tasks are Completed
- Set Event to Create & Update
- Expand Source & Target
- For Source Property select Active Stage
- Click Save
Set up the Condition
- Select the Functions tab, type findcount into the Search Functions input box and press enter
- Shift-click on the FindCount function to open the function wizard:
- Type Count Open Tasks for Stage in the Friendly Name field and leave the Type as Calculation
- Set Entity Name to task (select Task from the search options)
- Set Where Attribute to statecode (select Activity Status from the search options)
- Set Equals Value to 0 (i.e. Open)
- Set Select Attribute to activityid (select Task from the search options)
- Set Default Value to 0
- Leave No-Lock as the default value: true
- The completed wizard will look like this:
- Click Generate
- Select cell A4 and type >0
- We need to modify the FindCount function to filter results for the current Case (regarding field) and BPF Stage name
- Press F4 or right-click on the Decision Table and select Operations > Toggles Advanced Mode
- Select the Global Calculations tab
- Select cell B2 which contains the function created by the wizard in the previous step and click the + button in the top right to expand the Formula editor
- Cut the 'statecode' part of the function: FindCount('task','statecode','0','activityid','?','true'), leaving the cursor in its place
- Select the Functions tab and search for setfindand
- Select the SetFindAnd function to add it to the formula
- Replace the 'field1' text with the 'statecode' text from your clipboard
- Cut the '0' part of the FindCount, leaving the cursor in its place
- Select the SetFindAnd function to add it to the formula
- Replace the 'field1' text with the '0' text from your clipboard
- The function will now look like:
-
FindCount('task',SetFindAnd('statecode', 'field2', 'field3'),SetFindAnd('0', 'field2', 'field3'),'activityid','?','true')
-
- Replace the first 'field2' placeholder with 'regardingobjectid'
- Select the Explore tab and search for the Task entity
- Expand the Task node
- Ctrl-click Regarding (Value) to add 'regardingobjectid' to the formula
- Replace the first 'field3' placeholder with 'north52_bpfstage' (note that your custom field name will be different)
- Delete the remaining 'field2' text and replace with [phonetocaseprocess.incidentid]
- Select the Source tab and expand the Source node
- Select Incident (Value) to add [phonetocaseprocess.incidentid] to the formula
- Delete the remaining 'field3' text and replace with [phonetocaseprocess.activestageid_fmt]
- Select Active Stage (Value) to from the Source tab to add [phonetocaseprocess.activestageid] to the formula
- We need the formatted value of the Active Stage so need to add _fmt to this dynamic placeholder: [phonetocaseprocess.activestageid_fmt]
- The function will now look like:
-
FindCount('task',SetFindAnd('statecode','regardingobjectid','north52_bpfstage'),SetFindAnd('0', [phonetocaseprocess.incidentid], [phonetocaseprocess.activestageid_fmt]),'activityid','0','true')
-
- Close the Formula editor
- Click Save
Set up the Action
- Select the DecisionTable sheet
- Select cell B4
- Add the following text
-
'There are open tasks in the ' + [phonetocaseprocess.activestageid_fmt] + ' Stage'
- Click Save
At this point you can test to see whether you can progress stages with Task still open.
Formula - Check Predecessor is Completed and Change Task Status
This Decision Table formula will provide the logic which checks the predecessor Task is completed, before updated the Status. We use our custom Change Status field trigger the change from the Editable grid.
- Create a new formula, setting the following values in the Formula Guide:
- Source Entity set to Task
- Set Formula Type to Save - Perform Action
- Select the Decision Table editor
- Change the Name of the formula to Task - Check Predecessor is Completed and Change Status
- Set Event to Update
- Expand Source & Target
- For Source Property Ctrl-Click to select Change Status and Status Reason
- Click Save
Decision Sheet - Check Predecessor
The first sheet in this formula will check the status of the predecessor Task.
- Rename the sheet by double clicking on the sheet tab and changing the default DecisionTable name to Check Predecessor
- Select cell A2
- Select the Source tab
- Expand the Source node
- Select Predecessor (Value)
- Select cell A4
- Select the Functions tab
- Type containsdata into the search input box and press enter
- Ctrl-click the ContainsData function to add {{{ContainsData}} to cell A4
- Right-click column B and select Insert > Insert Condition
- Select cell B2
- Select the Source tab
- Expand Related (N:1)
- Expand task (north52_predecessor) (note that your field schema name will be different)
- Expand (Attributes)
- Select Status Reason
- Select cell B4
- Type !=
- Expand the Status Reason node in the Source tab
- Select Completed
- Cell B4 should now contain !={Completed}
- Select cell C4
- Select the Functions tab
- Type throwerror into the search input box and press enter
- Shift-click the ThrowError function to open the function wizard
- Leave the friendly name blank as we want to put the function directly in the cell
- Enter the following in the Enter string for error message field:
- The previous item "' + + '" must be completed before you can change this item
- Click Generate
- Place the cursor between the + +
- Select the Source tab
- Select Predecessor (Name)
- Cell C4 should now contain: ThrowError('The previous item ""' + {Predecessor (Name)} + '"" must be completed before you can change this item')
- Click Save
Decision Sheet - Update Status
The second sheet in this formula will change the status of the current Task based on the value selected in the Change Status field.
- Right-click on the Check Predecessor sheet and select Insert > Insert Decision Table
- Rename the sheet by double clicking on the sheet tab and changing the default DecisionTable2 name to Update Status
- Select cell A2
- Select the Source tab
- Expand Source
- Select Change Status {Value}
- Select cell A4
- Expand the Change Status {Value} node
- Select In Progress
- Select cell A5
- Select Completed
- Select cell B2
- Select Activity Status from the Source nodes
- Select cell B4
- Expand the the Activity Status node
- Select Open
- Select cell B5
- Select Completed
- Right-click on column C and select Insert > Insert Action
- Select cell C5
- Select Status Reason from the Source nodes
- Select cell C4
- Expand the the Status Reason node
- Select In Progress
- Select cell C5
- Select Completed
- Click Save
At this point you can test the predecessor check by trying to complete a task with an open predecessor:
Formula - Refresh Checklist Subgrid on Stage Change
This Decision Table formula will refresh the Checklist subgrid when the stage changes to show any newly created Tasks from the formula above.
- Create a new formula, setting the following values in the Formula Guide:
- Source Entity set to Case
- Set Formula Type to ClientSide - Perform Action
- Select the Classic editor
- Change the Name of the formula to Case - Refresh Checklist Subgrid on Stage Change
- Set Event to Create & Update
- Expand Source & Target
- For Source Property select OnStageChange for the relevant form
- Select the Functions tab
- Type refresh into the search input box and press enter
- Select the RefreshSubGrid function to add RefreshSubGrid('gridname') to the editor
- Delete the 'gridname' placeholder text including the quotes
- Select the Source tab
- Expand Forms
- Expand the form with the Checklist sub-grid (in our case we called it Case - Checklist Items)
- Expand the Tab which contains the Checklist sub-grid
- Expand the Section which contains the Checklist sub-grid
- Select the sub-grid labelled Task Checklist (as defined when the sub-grid was added to the form)
- The function should now look like: RefreshSubGrid('TaskChecklist')
- Click Save
- Select N52 Commands > Publish Formula to bind the formula to the form
Test by creating a new case and moving through to the next stage, observing that the checklist sub-grid refreshes.
Testing
You are now ready to do a full test. Create new Case records changing the Case Type and observing the different checklist Tasks that are created.