cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
itsmelmon
Helper I
Helper I

Message person on Shift in Teams

I want to setup a reminder message in teams, to remind people to complete an inspection when their shift starts. How can I get the user who is on an active shift? So that I can then message them. 

 

So far I've got a scheduled flow, followed by `Get a Shift`, followed by `Post a message as the flow bot to a user`  but I don't know how to find the Current Shift, or whether there is a better approach. 

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
Expiscornovus
Super User
Super User

Hi @itsmelmon ,
 
I believe this would be possible by using the start end end date an comparing it to the current date time with the utcnow(). However, in order to make this to work I am converting the times from Shifts and the current time to ticks per minute.
 
In my example I am using the List Shifts action btw.
 
1. Add a List All Shifts action

2. Add a condition action and add the following two expressions to it. The first one is looking at the start time and the second one at the end time of the shift. In both cases I am converting it to ticks per minute (that's why I am dividing it by 600000000). And I am using an empty to check to ignore the field value if it's empty. I noticed that some shifts where listed without start times.

 

Update expression below. Had a small typo.

 

if(empty(items('Apply_to_each')?['sharedShift/startDateTime']), 0, div(ticks(items('Apply_to_each')?['sharedShift/startDateTime']),600000000))

 

 

is less than or equal to 

 

 

div(ticks(formatdatetime(utcnow(), 'yyyy-MM-ddTHH:mm:ssZ')), 600000000)

 

 

 

And I am also using

 

 

if(empty(items('Apply_to_each')?['sharedShift/endDateTime']), 0, div(ticks(items('Apply_to_each')?['sharedShift/endDateTime']),600000000))

 

 

is greater than or equal to

 

 

div(ticks(formatdatetime(utcnow(), 'yyyy-MM-ddTHH:mm:ssZ')), 600000000)

 

 

 

listshifts_condition.png

3. Collected the assigned to user id and post your message to teams 🙂

 

Hope this helps a bit?

View solution in original post

5 REPLIES 5
Expiscornovus
Super User
Super User

Hi @itsmelmon ,
 
I believe this would be possible by using the start end end date an comparing it to the current date time with the utcnow(). However, in order to make this to work I am converting the times from Shifts and the current time to ticks per minute.
 
In my example I am using the List Shifts action btw.
 
1. Add a List All Shifts action

2. Add a condition action and add the following two expressions to it. The first one is looking at the start time and the second one at the end time of the shift. In both cases I am converting it to ticks per minute (that's why I am dividing it by 600000000). And I am using an empty to check to ignore the field value if it's empty. I noticed that some shifts where listed without start times.

 

Update expression below. Had a small typo.

 

if(empty(items('Apply_to_each')?['sharedShift/startDateTime']), 0, div(ticks(items('Apply_to_each')?['sharedShift/startDateTime']),600000000))

 

 

is less than or equal to 

 

 

div(ticks(formatdatetime(utcnow(), 'yyyy-MM-ddTHH:mm:ssZ')), 600000000)

 

 

 

And I am also using

 

 

if(empty(items('Apply_to_each')?['sharedShift/endDateTime']), 0, div(ticks(items('Apply_to_each')?['sharedShift/endDateTime']),600000000))

 

 

is greater than or equal to

 

 

div(ticks(formatdatetime(utcnow(), 'yyyy-MM-ddTHH:mm:ssZ')), 600000000)

 

 

 

listshifts_condition.png

3. Collected the assigned to user id and post your message to teams 🙂

 

Hope this helps a bit?

Great - thank you! One question - what is the first "equal to" expression on your condition block?

Expiscornovus
Super User
Super User

@itsmelmon, that's the schedulinggroupid. I only wanted to use shifts from a specific group, in my case: TAG_e936e338-e6f6-4de2-a044-7bbc1f3314c0

@Expiscornovus Fantastic - thanks. I have just tried to run this, but it has thrown an error "Unable to process template language expressions for action 'Condition' at line '1' and column '13706': 'The template language function 'lessOrEquals' expects two parameter of matching types. The function was invoked with values of type 'String' and 'Integer' that do not match.'."

 

I believe the term:

 

if(empty(items('Apply_to_each')?['sharedShift/startDateTime']), 'empty', div(ticks(items('Apply_to_each')?['sharedShift/startDateTime']),600000000))
 
is returning a string?
Expiscornovus
Super User
Super User

Hi @itsmelmon,

 

You are right, I believe I made a copy/paste error in my post earlier. Sorry about that.

 

For both the startDateTime and endDatetime expressions it should be 0 instead of 'empty'.

 

if(empty(items('Apply_to_each')?['sharedShift/startDateTime']), 0, div(ticks(items('Apply_to_each')?['sharedShift/startDateTime']),600000000))
if(empty(items('Apply_to_each')?['sharedShift/endDateTime']), 0, div(ticks(items('Apply_to_each')?['sharedShift/endDateTime']),600000000))

 

 

 

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

New Ideas Forum MPA.jpg

A new place to submit your Ideas for Power Automate

Announcing a new way to share your feedback with the Power Automate Team.

MPA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

365 EduCon 768x460.png

Microsoft 365 EduCon

Join us for two optional days of workshops and a 3-day conference, you can choose from over 130 sessions in multiple tracks and 25 workshops.

Users online (3,605)