In the realm of calendar and scheduling applications, managing repeating events can be a complex task. In a recent project, our customer was looking to have an “Outlook-style” repeating events experience in a Power App. Creating event series in a canvas Power App can be achieved using Power Fx; however, we quickly encountered multiple complexities and resulting pages of Power Fx. We were able to greatly simplify the repeating event generation in the app by leveraging “tried and tested” RRULE libraries inside of a PCF control. Let’s dive in!

The Need

In our scenario, a company needs to complete various processes regularly. These processes consist of multiple tasks assigned to various people in advance to assist with capacity planning and the processes themselves need to be completed on various schedules. We needed to be able to assign and edit future instances several years in advance, so we needed to identify and generate the instances up-front rather than on the completion of the prior event.

Recurrences could be daily, weekly, monthly, or yearly and needed to support day specifications, nth day/week scenarios, and accommodate time.

Here are a few examples:

  • Payroll process to be completed bi-weekly by 5 pm on Fridays.
  • A data export process may need to be completed daily at 2 pm.
  • A client delivery task may need to be completed on the third Wednesday of each month

The Challenge

With Power Platform it is best to start with low code first and then extend with a code-first approach when necessary. Not only does that enable easier solution maintenance by a wider audience and allow more to take part in the development process, but it is generally also faster and simpler.

Supporting all the requirements with Power Fx proved much more challenging than we anticipated. We had what would equate to pages of code in Power Fx and thought we were close to completion when we started running into challenges. For example, how could we easily account for leap-year scenarios? How do we address daylight savings time? How about when the users are distributed globally and in varying time zones? The final nail in the coffin was when the need arose to re-use these re-occurrence settings while still taking into consideration the time zones. We quickly found that our implementation became fragile at best.

RRULE and Its Benefits

This is where RRULE comes into play. RRULE stands for “recurrence rule”, which is a standard for defining the patterns of recurring events. It’s a powerful tool that helps to specify the criteria for generating occurrences of repeating events. RRULE is based on the iCalendar (RFC 5545) specification, which is widely used in various calendar applications like Google Calendar, Microsoft Outlook, and Apple Calendar. The specification defines a string format to represent complex repeating patterns such as “every third Friday” or “the second Tuesday of every month.”

The primary advantage of using RRULE is its ability to describe a wide range of recurrence patterns in a concise and standardized way. This makes it highly interoperable and ideal for use in scheduling applications where events need to repeat according to complex rules. It drops the need for manually inputting each occurrence of an event, thereby saving time and reducing the risk of errors. When configuration settings are provided, an “RRULE string” is produced. This string can then be used in reverse to repeat the same configuration settings while being agnostic to a time zone. For us, this was great as it allowed for the recurrence settings to be saved without needing a complex data model and enabled the recurrence to be processed via means other than just via the front-end, for example, providing the RRULE string to a plugin for processing.

Various open-source libraries are available to assist developers in implementing RRULE in their applications. Rrule.Js is one such library written in JavaScript by Jakub Roztocil and which we found aligned with our needs. This JavaScript library provides a straightforward API for working with recurrence rules. It can parse RRULE strings, generate occurrences of events, and even provide human-readable descriptions of the rules. Not only did it support our needs, but it is well documented, has been around for several years, and used by several other larger projects we found.

Using rrule.js in PCF controls for Power Platform

The Power Platform provides a framework for building custom controls called Power Apps Component Framework (PCF). PCF controls enable the use of traditional development to make controls that can then be used within Power Apps. In our case, we already had a UI but the rrule.js library was able to provide the business logic. While it might seem odd to create a PCF without a UI, that is exactly what we did which also enabled more flexibility for future UI use cases while still benefiting from the speed to value that the canvas experience of Power Apps provides.

Creating a PCF control could seem like a daunting task, and creating a project from scratch certainly could be. For our purposes, the challenging work had already been done by Jakub and the community supporting the RRULE project and our efforts were primarily centered around mapping input/output properties. Ultimately, the amount of code required in the PCF was much less than the mountain of Power Fx we had amassed in our prior implementation.

Conclusion

This opportunity provided us with several key learnings that we will certainly carry forward on future projects.

Without a doubt, low code enables development to take place at a faster pace. That doesn’t always mean that low code = less complexity. There are some instances where traditional development can be used in specific elements of a low-code Power Platform to reduce complexity.

Finally, a large element of Power Platform is the ability to re-use and tap into the collective thought of the wider community of makers. With code-first extensibility points such as PCF components, this re-use doesn’t have to stop with items made with low code; rather, it can also extend to the larger open-source community.

Do you think RRULE could help you in your next Power Platform project? If so, we have published the PCF control as open-source and would love for you to check it out, use it in your next project, contribute to evolve it further, or of course raise an issue if you encounter a struggle.