Use Template Tasks to separate data from logic

Shows an animated gif of a Model-Driven App. The App shows a Case record with the Tasks tab selected. It opens the Custom Page Dialog - Task Generator and selects a few items. Corresponding Tasks are generated and related to the Case.

In today’s data-driven world, it’s becoming increasingly important to separate data from logic when building applications. This separation not only helps keep your code organized and maintainable but also makes it easier to manage and work with your data. In this blog post, we’ll explore how to use Template Tasks to separate data from logic and make your applications more efficient and easier to manage.

I will do this by expanding my previous blogpost where we generate Tasks using a Custom Page. In that blogpost I show how to generate Tasks to help the user in their work. However for simplicity it did not contain a Description, or even all fields. Thus the Power FX logic looks pretty clean. If we want to keep it clean we can separate the data by using Template Tasks. By storing the data in Dataverse and using template tasks to generate tasks based on logic inside the Custom Page, you can create a more scalable and flexible workflow.

Shows the Power FX code before we add all fields. It's relatively clean and readable.
Relatively clean Power FX

Anyone can edit Template Tasks

The main benefit of separating the data from the logic is that everyone can edit the Template Tasks. Which means if someone decide they need to add detailed description to a Task, they can do so without editing the Power FX in the Custom Page. You can surface the Template Tasks inside a special administrator Model-App, or use a security role to show specific views and forms.

It will also make your app logic more clear. In my previous blogpost we already had a switch and several if statements. If we also add large descriptions, like the example below, it will be very hard to read the actual logic. Creating readable and simple to understand logic is still an important skill to have, even if you are using low-code!

Shows Power FX code with all fields entered to generate a Task with a large task description.
All fields entered makes for messy Power FX

Set-up Task Templates

Now that we know why it’s a good idea to use Task Templates, let’s talk how you can set this up. First I add 2 new columns to the standard Task table.

  1. Is Template Task. A Yes/No column to indicate if this Task is a Template
  2. Type. A Choice field which we will fill with all different template Tasks we want to generate.
Shows the "Is Template Task" Column and it's properties
“Is Template Task” Column
Shows the "Task Type" Column and it's properties.
“Task Type” Column

I also create a specific admin Form to create and edit a Template Task. For each Task we generate in the Custom Page I create a Template Task with the corresponding Task Type. I set the Yes/No field to yes when it’s a Template Task.

Shows the choices for Task Type column.
Task Type Choices

Revisit the Power FX logic in the Custom Page

We now have the basis set up to expand our Custom Page. I want a collection of all Template Tasks so I can use them later to generate Tasks. On the OnVisible of the Custom Page add the following Power FX:

ClearCollect(colTemplateTasks, Filter(Tasks, 'Is Template Task' = 'Is Template Task (Tasks)'.Yes));

Now on the OnSelect of the Generate button we can add LookUps to the Subject and Description of our Task Templates.

Shows the changed Power FX code which now looks up the Data from Task Templates in Dataverse instead of creating all that data in the code.
Power Fx looking up the data from the Template Task

And for the end result when we generate a Task we get the same task. But with the added (and important) benefits of relatively clean logic and the ability for a business user to change the data of the Task description.

Shows the Generated Task inside the Model-Driven Power App
Generated Task

Leave a Reply

Your email address will not be published. Required fields are marked *