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 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.

Power Platform Call June 2022 768x460.png

Power Platform Community Call

Join us for the next call on June 15, 2022 at 8am PDT.

PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

PA.JPG

New Release Planning Portal (Preview)

Check out our new release planning portal, an interactive way to plan and prepare for upcoming features in Power Platform.

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