cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
JennyinIndy
Frequent Visitor

Validation for last 7 days in Power Apps or Automate?

Hello!  I am looking for some assistance.

I have a Power App that allows users to enter a safety activity.  The safety activity is a choice field with 6 different options.   They can enter each activity once every 7 days.  When they submit the form, it starts a flow that goes through an approval process.  Right now, the first part of the approval process is manual to check if they have submitted that activity in the last 7 days.  

I would like to make that part automated either in Power Apps or Flow.  I tried creating a view on the Sharepoint list for the last 7 days.  I was able to create a flow and get items based on that view. I was planning on having it count is the safety activity count is greater than 1, but it does not work since it is a choice field.

 

Any suggestions would be appreciated!

 

 

1 ACCEPTED SOLUTION

Accepted Solutions

@JennyinIndy ,

That was the idea the the else bit

With(
   {
      wList:
      Filter(
         YourActivityListName,
         YourDateField,
         Descending
      )
   },
   If(
      DateDiff(
         Lookup(
            wList,
            YourUserField=User().Fullname
         ).YourDateField,
         Today()
      ) < 7,
      Notify("You have an activity in the last 7 days")
   ),
   SubmitForm(YourFormName)
)

This will either give the message or submit the form.

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

View solution in original post

6 REPLIES 6
WarrenBelz
Super User
Super User

Hi @JennyinIndy ,

Assuming you have the user's name and the date of the last Activity in your list, you would do something like this

With(
   {
      wList:
      Filter(
         YourActivityListName,
         YourDateField,
         Descending
      )
   },
   If(
      DateDiff(
         Lookup(
            wList,
            YourUserField=User().Fullname
         ).YourDateField,
         Today()
      ) < 7,
      Notify("You have an activity in the last 7 days")
   )
)

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

JennyinIndy
Frequent Visitor

Thank you.  Would I add this code to the onsubmit field?

@JennyinIndy ,

I cannot see your model, but you would generally put this before your save code, with the save being the "else" at the end.

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

 

Hi @JennyinIndy ,

Just checking if you got the result you were looking for on this thread. Happy to help further if not.

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

@WarrenBelz 

Thanks for responding.  

In your example above 

Submitter would be the user field.  

Event Date would be the date field. 

Safety Activity could be one of several choices.  Attend Safety Training and Instruct Safety Training would be two of the choices.  They can both attend and instruct safety training once every 7 days.  They would not be able to attend safety training twice in 7 days.  

 

After they get notified that they have already completed that activity, is there a way to keep them from submitting the form until they change it?

 

Thank you,

 

Jenny

 

@JennyinIndy ,

That was the idea the the else bit

With(
   {
      wList:
      Filter(
         YourActivityListName,
         YourDateField,
         Descending
      )
   },
   If(
      DateDiff(
         Lookup(
            wList,
            YourUserField=User().Fullname
         ).YourDateField,
         Today()
      ) < 7,
      Notify("You have an activity in the last 7 days")
   ),
   SubmitForm(YourFormName)
)

This will either give the message or submit the form.

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Community Call Conversations

Introducing the Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (3,178)