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 III
Super User III

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.

View solution in original post

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

MBAS Attendee Badge

Claim Your Badge & Digital Swag!

Check out how to claim yours today!

secondImage

Are Your Ready?

Test your skills now with the Cloud Skill Challenge.

Top Solution Authors
Top Kudoed Authors
Users online (52,480)