web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Power Automate - Building Flows
Answered

Creating an event

(0) ShareShare
ReportReport
Posted on by 368

I have an approval flow for PTO requests.
Essentially the flow is triggered when
     response is received in MS Form

     an approval process takes place

     an item is created on SP list

     AND and an 'All day' event showing as 'free' is created in Director's calendar  (all day event is preferred due to where/how this shows up on the calendar) 
The flow works perfectly if the PTO request is for longer than 1 day.  If PTO is only 1 day then an error message of 'all day event must be at least 24 hours' is given. 
How do I establish first day of leave request as 11/9/2020 00:00:00 and last day of leave request as 11/9/2020 24:00:00?
The alternative would be to change wording on MS Form to
     first day off work
     first day back to work
I would rather not do that if possible.

PeggyLang_0-1604950085190.png

 

I have the same question (0)
  • tom_riha Profile Picture
    10,179 Most Valuable Professional on at
    Re: Creating an event

    Hello @PeggyLang ,

    the end date should be 11/10/2020 00:00:00 exactly in your case, that will give you 1 full day off from 11/09/2020 (but if it's even 00:00:01 it'll be resolved as 2 full days).

    I'd add a condition to your flow before you create the event. If 'start date is equal to end date', use the following expressions as start/end date.

    startOfDay('<startDate>') :this will give you the start date @00:00:00
    addDays(startOfDay('<startDate>'),1) :this will give you the next day @00:00:00

    image.png

     If 'start date not equals end date' use the start date and end date from the form.

  • PeggyLang Profile Picture
    368 on at
    Re: Creating an event

    @tom_riha I like where you are going here.  I didn't think of that.  However, even if I did I'm unclear how to accomplish this.  See Screenshot below.  I think I have my 'if start date = end date' condition in the right place, but when I try to 'initialize variable' in the 'yes' tree I am returned with 'The operation 'initialize variable' can only be used at top level'.  Obviously I'm choosing the incorrect Action, but I don't know what to choose instead.

    PeggyLang_0-1605027027085.png

     

  • tom_riha Profile Picture
    10,179 Most Valuable Professional on at
    Re: Creating an event

    Hello @PeggyLang ,

    'Initialize variable' must be at the top level, it can't be in any condition/loop/etc., ideally right after the trigger. But you don't need any variable, you can use expression directly in the 'Create event' action.

  • PeggyLang Profile Picture
    368 on at
    Re: Creating an event

    @tom_riha 

    I'm having a devil of a time creating the expression. 

    I'm assuming my expression will be a combination of expression & dynamic content.

    Based on this assumption, my expression begins to look like the below;

    Start time =  startOfDay('outputs('Create_item_2')?['body/Lastdateofleave']')

    End time = addDays(startOfDay('outputs('Create_item_2')?['body/Lastdateofleave']'),1)

    second screenshot.jpgfirst screenshot.jpgHowever, when I input that I am returned with the error 'The expression is invalid' I know this is going to work just as soon as I get the actual syntax correct.

    Screenshots above are added in incorrect order, first should actually be second.

  • Verified answer
    tom_riha Profile Picture
    10,179 Most Valuable Professional on at
    Re: Creating an event

    Hello @PeggyLang ,

    when you're using dynamic content, you don't need the apostrophes, try it as below.

     

    Start time = startOfDay(outputs('Create_item_2')?['body/Lastdateofleave'])
    
    End time = addDays(startOfDay(outputs('Create_item_2')?['body/Lastdateofleave']),1)

     

  • PeggyLang Profile Picture
    368 on at
    Re: Creating an event

    @tom_riha PHEW!!!
    This was frustrating for me (maybe you as well  🤣).
    I went into the expression many times to insert dynamic content and sometimes after I typed in the expression, placed my cursor to where I want the dynamic content and then clicked on dynamic content the expression would disappear, sometimes the dynamic content would not show me the correct options, sometimes I would be successful in getting the expression AND the dynamic content in, save and test only to find an error, then when going back into edit would find the dynamic content had disappeared . . . Really weird, inconsistent things were happening.  So . . . I signed out, rebooted, signed back in, edited flow and ran.  It WORKS!!!  I've only run it once (I'm afraid to jinx it and try it again) but I will have to run it again to be extra sure that it is working and nothing strange is going on.
    I greatly appreciate your knowledge, time and patience working through this with me!!!

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Chiara Carbone – Community Spotlight

We are honored to recognize Chiara Carbone as our Community Spotlight for November…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 614 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 401 Moderator

#3
chiaraalina Profile Picture

chiaraalina 282

Last 30 days Overall leaderboard