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

Create multiple items in Sharepoint list based on number of occurrences in calendar

Hi all,

 

I have a PowerApps with calendar event entry, one feature is user can decide if the event is recurrent and how many times the occurrences is.

 

For example, they created an event and they want this event to be recurrent on monthly basis for 12 occurrences.

So I need to save this event 12 times with same information (i.e location, required attendees) but different dates.

 

I am making a flow to save these occurrences in SharePoint list but I am already stuck on how to loop it. I already have for one time entry but how can I do this multiple times.

 

PowerPlatform_Calendar.jpg

 

Any help is appreciated. Thank you!

 

 

Regards,

May

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
t-imoreira
Microsoft
Microsoft

Hello!

 

I believe I found a solution for your problem. To start, I defined 2 variables: the number_ocurrences (will be set with the number of dates you wanna create) and the counter (will increment the initial date ).

 

As a condition, sharepoint items will be created until the counter is equal to the number_ocurrences variable. To achieve this condition, everytime that a sharepoint item is created the counter should be incremented by one.

 

To create the sharepoint item with the correct date, the following expression was used:

 

addToTime(utcNow(),variables('counter'),'Month','yyyy-MM-dd')

 

This expression will add to the 'utcNow' (that in your case should be the initial date) and will add the value defined in the 'counter' variable to the Months.

I believe this logic will solve your problem.

Bellow you can see a print of my flow.

 

timoreira_0-1635853036436.png

 

Any question that you have feel free to ask.

 

-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

View solution in original post

10 REPLIES 10
t-imoreira
Microsoft
Microsoft

Hello!

 

I believe I found a solution for your problem. To start, I defined 2 variables: the number_ocurrences (will be set with the number of dates you wanna create) and the counter (will increment the initial date ).

 

As a condition, sharepoint items will be created until the counter is equal to the number_ocurrences variable. To achieve this condition, everytime that a sharepoint item is created the counter should be incremented by one.

 

To create the sharepoint item with the correct date, the following expression was used:

 

addToTime(utcNow(),variables('counter'),'Month','yyyy-MM-dd')

 

This expression will add to the 'utcNow' (that in your case should be the initial date) and will add the value defined in the 'counter' variable to the Months.

I believe this logic will solve your problem.

Bellow you can see a print of my flow.

 

timoreira_0-1635853036436.png

 

Any question that you have feel free to ask.

 

-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

Hi @t-imoreira ,

 

Thank you so much! 

I can understand the concept now. However, I run an error. Maybe you can take a look at it?

 

I have to use Switch because I have a choice column in the SP on the recurrences: Daily, Weekly, Month, Yearly. 

 

But when I am trying to save it, here's an error on template validation on the default trigger. Do you know how to solve this? Thank you again!

 

 

Error.jpgerror1.jpg

 

 

 

Regards,

M

t-imoreira
Microsoft
Microsoft

Hello!

 

I'm glad you understood the logic behind my previous answer! Regarding this new issue, I will present bellow some troubleshooting steps to better understand where is the problem.

  1. Can you please delete the trigger action "When a file is created" and add the "Site Address" and "List Name" using the dropdown option? Sometimes wrong url's can cause problems in these kind of triggers.
  2. Have you used any additional trigger conditions in the action "When a file is created" behind the "Site Address" and the "List Name"? Just to be sure that the problem is not from something not visible in the flow. To check if no extra condition is selected, you can follow the instructions bellow, where your selections should be like the ones shown in the pictures.

 

timoreira_0-1635950172957.pngtimoreira_1-1635950211421.png

 

 

If the suggestion from point 1 doesn't solve the issue, and the answer to point 2 is no, I have another suggestion for you. To discover where is the problem in the flow, can you run the flow step by step, adding each action at the time and saving the flow at each step? In this way we will be able to know the action that is causing the problem.


Any question that you have feel free to ask.

 

-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

 

Hi again,

 

I already solved the other errors but I noticed the date output. The first date (incremented) is the same as the original date. The original entry is Testing the Date output - 11/14/2021. It should be repeated 3 times. The next date should be 11/15/2021 then 11/16/2021 then 11/17/2021.

 

date_incremented.jpg

I am using this on the date

addToTime(triggerOutputs()?['body/Date'],variables('counter'),'Day','yyyy-MM-dd')

 

Thank you for your time! 🙂

 

Regards,

May

 

Hello again 🙂 

 

I believe the problem is in the increment of the variable 'counter'. Can you please confirm that you are using the action "Increment variable" (see printscreen below) after the "Create Item" action, and you are incrementing the counter?

 

timoreira_0-1636632868138.png

 

Look forward to your reply.

 

Hi,

 

Yes. I am using the increment 🙂

do until.jpg

 

/M

Hello!

Can you please confirm me if the same error occurs both on 'Daily' and 'Weekly' options?

 

Look forward to your reply.

Hi again,

 

I tested Monthly, Weekly and Yearly.

Testing Daily.jpg

I think the dates are off but this might be because if its 30 or 31 days in a month.

 

Thank you so much!

 

 

Regards,

May

t-imoreira
Microsoft
Microsoft

Hello again.

To avoid the problem of the different days of a month, you can take advantage of the third parameter of the addToTime function.

 

Bellow, where you have [unit], you can input any of the following options:

Second, Minute, Hour, Day, Week, Month or Year (don't forget to include '')

 

 

addToTime(triggerOutputs()?['body/Date'],variables('counter'),[unit],'yyyy-MM-dd')

 

 

So, accordingly with the previous printscreen that you sent, what is incorrect? Just to clarify the problem, because from what I see it is adding days, weeks and years to the original date ('Testing').

Look forward to your reply.

 

Hi,

 

Yes, I tried that code 🙂

addToTime(triggerOutputs()?['body/Date'],variables('counter'),'Day','yyyy-MM-dd')
addToTime(triggerOutputs()?['body/Date'],variables('counter'),'Month','yyyy-MM-dd')
addToTime(triggerOutputs()?['body/Date'],variables('counter'),'Week','yyyy-MM-dd')
addToTime(triggerOutputs()?['body/Date'],variables('counter'),'Year','yyyy-MM-dd')

 

But the date output is off by 1 day for Weekly, Monthly and Yearly.

Testing Daily_01.jpg

 

And for Daily. The first output date (incremented) is same as original date.

date_incremented_01.jpg

 

 

Any idea, why this is happening? Thank you again! 🙂

 

Regards,

May

 

Helpful resources

Announcements
2022 Release Wave 1 760x460.png

2022 Release Wave 1 Plan

Power Platform release plan for the 2022 release wave 1 describes all new features releasing from April 2022 through September 2022.

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Top Solution Authors
Top Kudoed Authors
Users online (1,726)