What are Activities?
In Microsoft Dataverse, activities are tasks that an individual or a team can performs pertaining to communication. For example, sending an email, making a phone call, setting up an appointment etc, All activities have some basic properties like subject, description, and they are all related to time (e.g. start time, stop time, due date, duration etc.). You can also create custom ones if needed. To learn more about them, click here.
Model-Driven App Timeline
Most people who have worked with model-driven apps, will know what a timeline is. It shows activities related to the record you are on. For example, in the image below, the timeline shows all activities related to the account "A. Datum Corporation (sample)":
The different types
There are several different activity types:
- Phone Calls
- Email Messages
- Tasks
- Appointments
- Faxes
- Letters
Each one of these has its own Dataverse table. That being said, when an appointment, as an example, is created, it creates a new record in both the Activity and the Appointment tables. The two records are then linked to each other. Some basic/common columns are available on the Activity table whereas some specific columns are available in the respective tables like Tasks, Appointments etc.
Activities and canvas apps
Activities in a model-driven app work like a charm. However, in a canvas app, working with them can be challenging. The main reason for this is that the Activity Type column, that denotes whether an activity is an email or a phone call or something else, IS NOT accessible or available within canvas apps.
Filtering by types
If you want to show a specific type of activity in your canvas app, you can simply use the related table. For example, use the Tasks table if you want to show tasks, or use the Phone Calls table if you want to show calls.
However, if you want to show a consolidated list of more than one type, this is when it gets challenging.
To overcome this challenge, we will make use of Dataverse views. The Activity Type column is accessible there. For this example, we will assume we only want to show Appointments and Tasks.
Go to make.powerapps.com -> Tables -> Activity -> Views -> New View and set the filters as shown below.
Here is a simple consolidated view of all activities using the Activity table:
To display all activities in a gallery, set the Items property of the gallery to:
Search(
Activities,
txtSubject_Activities.Value,
Subject
)
To show only tasks and appointments in a gallery, use the view we created above in the Items property of the gallery as shown below:
Search(
Filter(
Activities,
'Activities (Views)'.'Filtered Activities View'
),
txtSubject_FilteredActivities.Value,
Subject
)
With this Items property, the gallery looks like this:
Displaying Activity Type
While the above gallery is cool, it does not tell me which record is an appointment and which is a task. Since, the Activity Type column isn't available in canvas apps, it is not as straight forward as setting the Value property of a label to
ThisItem.'Activity Type'
I mentioned above in this blog post, that when you create an appointment (or a task or any other activity), two records get created - one in the Activity table and the other one in the appropriate specific table, Appointment in this example.
So, set the Value property of a label to the following to show the activity type:
If(
CountRows(ThisItem.Appointments.Appointment) > 0,
"Appointment - ",
"Task - "
) & ThisItem.Subject
ThisItem.Appointments is the list of related records in the Appointment table for a given record in the Activity table. If the count of this is greater than 0 (you can even do = 1), then that means it is an appointment. Since this list is filtered to only show appointments and tasks, the only other possibility is that the activity is a task.
You can also set the Value property of the label to the following to show the activity type:
If(
IsType(ThisItem, Appointments),
"Appointment - ",
"Task - "
)
To learn more about the IsType function, click here.
The gallery will look like this with the above code:
To make it look better, you can add an icon and display the appropriate icon based on the code above. Set the Icon property of the icon control in the gallery to:
If(
CountRows(ThisItem.Appointments.Appointment) > 0,
"Calendar",
"AppsList"
)
You can also set the Icon property to the following code to get the same result:
If(
IsType(ThisItem, Appointments),
"Calendar",
"AppsList"
)
This is how the gallery will look:
Accessing specific columns
As we discussed above, some basic/common columns are available in the Activity table. However, there are certain columns that are specific to each type and they are available in the appropriate type-specific tables.
For example, tasks have a column Start Date but appointments don't. For appointments, similar columns are Original Start Date and Actual Start.
In the gallery above, to show these values in a label, set its Value property to:
If(
IsType(
ThisItem,
Tasks
),
AsType(
ThisItem,
Tasks
).'Start Date',
IsType(
ThisItem,
Appointments
),
AsType(
ThisItem,
Appointments
).'Actual Start'
)
Since the gallery has just 2 types, the 2nd IsType above (to check for appointments) isn't really necessary. But whenever I use AsType to "cast" a record to another table, I do an IsType just as an added precaution else the code will error out if there is a record in the gallery that is neither a task nor an appointment.
Conclusion
Activities are a very powerful component of Dataverse. They work seamlessly in model-driven apps. In canvas apps, the biggest limitation is that there is no access to the Activity Type column. However, with the help of Dataverse views, relationships, and the use of AsType/IsType functions, you can overcome that limitation.
Recent articles
- Can ChatGPT really help with building Power Apps?
- Have you played Battleship? In Power Apps?
- How to fix a weird behavior with search function?