Power Apps and marking vacations

The hour reporting application at our workplace is an excellent example of Power Platform development. Initially, we did a really light implementation (for both desktop and mobile use) to report hours.

As the number of work orders and employees increased, the need to highlight specific work orders as “favorites” was raised. This functionality was implemented, which again made hour reporting easier.

The next small modification was the ability to copy an existing record.

The tool is gradually being developed as needed.

This example brings us nicely to the topic of today’s post.

Marking vacations

On the last day before my winter vacation, I once again did the same familiar routines

  • Added 7.5h vacation marking for each day (annual vacation)
  • Marked to my calendar that I was on vacation
  • Edited and timed an automatic out of office reply in email
  • Marked in shared vacation calendar (in SharePoint) that I was on vacation

At the same time, I decided that this was the last time I will be doing these manually. Before the summer vacations, there has to be a more meaningful way to get these steps done. This was the start of a vacation app, which ended up as an additional feature in our hour reporting app.

How is a solution like this created?

User Interface (Power Apps)

My Vacations can be found in the hour reporting application from the menu.

All of the functionality is on one screen. The form on the left is used to add vacations, which will appear in the gallery on the right.

A new vacation is added by specifying the following information

  • Start and end date of the vacation
  • Description for the markings (Vacation by default)
  • Is the vacation added to shared vacation calendar?
  • Is the vacation added to personal calendar? If so, under what title?
  • Is an automatic out of office message set for the duration of the vacation? The message is generated automatically, but it can be freely edited by the user

The data is stored in a separate table in Dataverse (Employee vacation). This way, vacation markings created in different systems can be canceled if necessary.

The actions performed by the tool are divided into their own flows, which are launched in parallel (Concurrent) from the Save button.

What happens in these flows?

Hour markings (Flow)

First, hour markings are created for the vacation period.

  • Load the work order id corresponding to annual vacation from environment variable
  • Parse the parameter obtained from Power Apps in JSON format (vacation days, descriptions and user id)
  • Go through the vacation days and add an hour marking for each

This is quite basic stuff. But how do we create the hour markings for weekdays only? After all, vacations can last for several weeks.

This is handled in Power Apps. There, a collection is created that contains only weekdays in the range specified by the user.

  1. Use the Sequence command to create a table with ascending numbers for a given vacation period. So for a week’s vacation [0,1,2,3,4,5,6]
  2. Using this table, we go through the vacation period and add only weekdays (Weekday between 2 and 6) to the collection (colVacationDays)
  3. At the same time, a description and user ID are added to the collection
ForAll(Sequence(dpEnd.SelectedDate - dpStart.SelectedDate + 1,0),
 If(
    Weekday(dpStart.SelectedDate + Value) > 1 
      And Weekday(dpStart.SelectedDate + Value) < 7,
    Collect(
      colVacationDays,
      {
       date: dpStart.SelectedDate + Value,
       Description: inpHourEntryDescription.Text,
       User: varCurrentCDSUser.User
      }
    )
  )
)

The generated collection is then passed to Flow in JSON format.

Addhourentriesforthevacation.Run(JSON(colVacationDays,JSONFormat.IndentFour))

This way, the flow itself stays nice and simple.

Calendar marking in a shared calendar (Flow)

The shared vacation calendar can be found in SharePoint. A marking is created there for the vacation period. It is essential to return the identifier of the calendar marking to Power Apps. We want to save it so that the marking can be easily deleted if needed.

The flow that is initiated from Power Apps uses the connections of the user. The calendar entry is therefore created in their name.

The vacation marking looks like this.

Calendar marking in personal calendar (Flow)

Making a marking on a personal calendar is a step harder. A user can have multiple calendars, so first you need to find out which of these is their default calendar.

  • Retrieve all of users calendars
  • Filter the calendar array using Filter array, so that only the default calendars remain
  • Make a calendar marking in the default calendar (there is only one)

After that, everything is easy. Here too, we must return the id of the created calendar marking to Power Apps.

And again… Since the flow is run on the connections of the Power Apps user, their personal calendar is modified.

Out of office message (Flow)

The last flow sets a timed out of office message for the user.

Like so.

Saving the vacation row to Dataverse

Once the different flows have done their job, the employee’s vacation row is saved in the Employee Vacations table in Power Apps. This way, the ids for created calendar markings can be included as well.

Patch(
  'Employee vacations',
  Defaults('Employee vacations'),
  {
    Name: varCurrentUser.FullName & " " & dpStart.SelectedDate & "-" & dpEnd.SelectedDate,
    Start: dpStart.SelectedDate,
    End: dpEnd.SelectedDate,
    'Create event in shared calendar': chkSharedCalendar.Value,
    'Create event in personal calendar': chkPersonalCalendar.Value,
    'Use Out of Office ': chkOutOfOffice.Value,
    'Personal calendar event id': varMyCalendarEventId,
    'Shared calendar event id': varSharedCalendarEventId
  }
)

The added vacation is displayed in the My Vacations gallery on the right.

More specifically, the gallery only shows vacations that have not ended yet. There is no need to cancel vacation markings that have already passed.

Filter('Employee vacations', 'Employee vacations (Views)'.'User own Vacations', End > Today())

Cancel vacation markings (Flow)

If the user wants to cancel a vacation marking, a flow is started from the trash can icon that

  • Deletes vacation markings for the duration of the vacation period
  • Sets the out of office message to inactive
  • Deletes the calendar marking from the shared calendar
  • Deletes the calendar marking from personal calendar
  • Deletes the vacation markings row form Dataverse

Cleaning (Flow)

Past vacation markings are not utilized anywhere. After all, the vacations can be found in hour markings and calendars. The old vacation markings are cleaned monthly from Dataverse.

Summary

Everything is now ready, and those manual routines will not be missed.

The solution has more upsides as well.

  • Not everyone has a habit of creating an out of office message and / or marking their vacation time in their personal calendar. And sometimes doing these steps is just simply forgotten. Now that everything is done from one place, this won’t (so easily) happen anymore.
  • An organization can provide its employees with a standardized out of office message. Or even more than one option.

If there are other routines in your organization in addition to these when starting a vacation, then just add separate steps for them too. Of course, you can automate processes not only with cloud flow but also with desktop flow (RPA).

Everything you can (easily and cost-effectively) automate, is worth to automate.

Show me more apps running on Power Platform!

Are you interested in seeing examples of the kinds of apps we’ve built for our customers & ourselves by using Power Apps, Power Automate and Power BI? Check out the Forward Forever App Gallery for ideas and inspiration on what your organization could also achieve with low-code apps.

Leave a Comment