This blog will discuss the way to pause the notification for the weekend. It means it stops the notification for the weekend and continues on Monday to send the notification.
Requirement
We had a requirement to notify when the case status is updated to urgent. But the case status is updated to ‘Urgent‘ when the case is not picked up or worked by anyone for 24 hours using the ‘Not Started‘ status. Pause the notification that was specific to the one time zone.
For example, Case created on Friday at 9 AM, Friday evening clocks stop counting and continue Monday at 8 AM. In this case, 24 hours will be calculated as
Fri 9 AM to 6 PM – 9 Hours
Mon 8 AM to 11 PM (Mid Night) – 15 Hours
Case Status will be updated to Urgent on Monday 11 PM.
Solution
- Find the Upcoming Friday Evening based on record created date
- Find the Upcoming Monday Morning based on the record created date
- Calculate the number of hours before the weekend
- Calculate the number of hours after the weekend
- Decide whether to change the status
Power Automate Flows
We have two flows for this use case.
- Scheduled Flow – Runs every x hour to set the Status to Urgent
- Automated Cloud Flow – Runs when the record is modified to send a notification
Now will walk through the flow of each action
Flow 1: Scheduled Flow
Flow Chart to calculate the number of hours Before and after the weekend
Flow Explanation
- Initialize below variables
- List rows and loop through the records
- Find Upcoming Friday and Monday
We need to find upcoming Friday and Monday based on the record-created date time. The below section will run for each record to be within each loop.
- Formulas are used to find upcoming Friday and Monday
Set CreatedOnitems(‘Apply_to_each_Account’)?[‘createdon’]Set Current TimeutcNow()Compose CreatedOnformatDateTime(variables(‘CreatedOn’), ‘yyyy-MM-ddTHH:mm:ss.fffZ’)Compose Current TimeformatDateTime(variables(‘Current Time’), ‘yyyy-MM-ddTHH:mm:ss.fffZ’)TargetTimeNowconvertFromUtc(variables(‘Current Time’), variables(‘Target Time Zone’))UpcomingFridayconvertToUtc(formatDateTime(concat(string(addDays(outputs(‘Compose_CreatedOn’), sub(5, dayOfWeek(outputs(‘Compose_CreatedOn’))), ‘yyyy-MM-dd’)), ‘ 18:00:00’), ‘yyyy-MM-ddTHH:mm:ss’), variables(‘Target Time Zone’))UpcomingMondayconvertToUtc(formatDateTime(concat(string(addDays(outputs(‘Compose_CreatedOn’), sub(8, dayOfWeek(outputs(‘Compose_CreatedOn’))), ‘yyyy-MM-dd’)), ‘ 08:00:00’), ‘yyyy-MM-ddTHH:mm:ss’), variables(‘Target Time Zone’))
- Condition Target Time less Than Upcoming Friday
less(outputs(‘Compose_Current_Time’), outputs(‘UpcomingFriday’))
- Set Before Weekend
div(sub(ticks(outputs(‘TargetTimeNow’)), ticks(convertFromUtc(outputs(‘Compose_Createdon’), variables(‘Target Time Zone’)))), 36000000000)div(sub(ticks(outputs(‘UpcomingFriday’)), ticks(outputs(‘Compose_Createdon’))), 36000000000)
- Condition Target Time Greater Than Upcoming Monday
greater(outputs(‘Compose_Current_Time’), outputs(‘UpcomingMonday’))
- Set After Weekend
div(sub(ticks(outputs(‘Compose_Current_Time’)), ticks(outputs(‘UpcomingMonday’))), 36000000000)
At this time, we have several hours before the weekend and after the weekend. So now add both together.
add(if(less(variables(‘BeforeWeekend’),0),0, variables(‘BeforeWeekend’)), variables(‘AfterWeekend’))
Outputs(‘Compose_Total_Hours’)
- Update the status to urgent when the total hours are more than 24 hours
Flow 2: Automated Cloud Flow – Runs when the record is modified to send a notification