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

Help me with load rules

Hello All,

I have created power apps form which handles Mobile purchase reimbursement requests. 

But i am stuck with the load rules of the app.  user submits the request from the app and request gets stored in the share point list which is working fine & Now all i want to do is when the same user opens the app it should go to the data source and check for the existing record for the user and if there is a record it should pull the Next purchase date and compare it with today's date. If the next purchase date is greater than or equal to today. It should allow him to home screen to submit the new request which should basically replace the existing record in the share point list. If the next purchase date is not lesser than today it should take him to a screen which says your next purchase date is 01/06/2022 please come back on this date.

 

I am calculating next purchase date using this formula - Purchase date + 2  years.

 

Please help me to achieve this.

 

Thanks,

CL

1 ACCEPTED SOLUTION

Accepted Solutions

In the "App" ssection - abover your screen list in the interface - there is an OnStart property. All the commands listed there will run before anything shows in the app. If you include:

Set(var_User, User());
in that list then you will have info about the current user - Name, email, photo. You can use that info to compare to your SP list.
Each list will have a Created by field, and you have an EMail field listed. You can generate a list of this users entries with this command - also in OnStart:
ClearCollect(col_Entry,Filter(SPList,Email=varUser.Email));
If(IsEmpty(col_Entry),Navigate(screen_New),Navigate(screen_ReOrder)
The second command will look at the list and if the person has an entry in the SP list they will be taken to the reorder area, if they do not they will be taken to the first time order screen.
On the re-order screen, create a Gallery. In the Items property use this:
Sort(col_Entry,PurchaseDate,Descending)
That will give you the list of the current users orders, with the newest on top
Create a button for a new order on that page. In the Visible property of the button you could put 
Today()>=NextPurchaseDate
Then the button would only show if the purchase is allowed. Alternately, You could also set up a similar If statement in the DisplayMode of the button. Then the button would show it would not be clickable.
If(Today()>=NextPurchaseDate, DisplyMode.Edit,DisplayMode.Disabled)
 
Hope this helps
 

View solution in original post

8 REPLIES 8
mdevaney
Super User
Super User

@Chiranth1992 
Please share a sample of the data you are pulling from SharePoint.  I need to know the column names, column types, and a few rows of sample data.

BrianS
Super User
Super User

When loading the app needs to check the SP list "created by" to see if it matches the current user. Set a variable on load to the current user and use that for the search. If there is no match you could navigate to the screen to create a new request. If there is a match, filter the gallery by there user name. Check the date match and have your "Submit "button's visible property (or view property) set so that it will only work if the date is correct. You could also have a pop up message set to the same if statement. 

If you just want to leave that single record you could just change the date to the current date and allow them to save it. Or you could generate a new record by copying the previous info into a new record with today's date. That way you would keep a running record of all orders. 

Hi @mdevaney

 

Please find the column names, all the columns data type is text except PurchaseDate and NextPurchase date in the date format.

How the lookup happens if there are mutliple record for the same user.

Chiranth1992_0-1595223641266.png

 

@BrianS I am new to powerapps. It would be great if you can help in details.

 

as you said, Look to splist to match the current user and compare the date by filtering the gallery.

How does it work if there are multiple record for the same user ?

In the "App" ssection - abover your screen list in the interface - there is an OnStart property. All the commands listed there will run before anything shows in the app. If you include:

Set(var_User, User());
in that list then you will have info about the current user - Name, email, photo. You can use that info to compare to your SP list.
Each list will have a Created by field, and you have an EMail field listed. You can generate a list of this users entries with this command - also in OnStart:
ClearCollect(col_Entry,Filter(SPList,Email=varUser.Email));
If(IsEmpty(col_Entry),Navigate(screen_New),Navigate(screen_ReOrder)
The second command will look at the list and if the person has an entry in the SP list they will be taken to the reorder area, if they do not they will be taken to the first time order screen.
On the re-order screen, create a Gallery. In the Items property use this:
Sort(col_Entry,PurchaseDate,Descending)
That will give you the list of the current users orders, with the newest on top
Create a button for a new order on that page. In the Visible property of the button you could put 
Today()>=NextPurchaseDate
Then the button would only show if the purchase is allowed. Alternately, You could also set up a similar If statement in the DisplayMode of the button. Then the button would show it would not be clickable.
If(Today()>=NextPurchaseDate, DisplyMode.Edit,DisplayMode.Disabled)
 
Hope this helps
 

@BrianS 

 

I followed your instruction and i was able to create reorder screen to show the list of requests from the user and if it find the record in SP for the current user it is taking me to reorder screen but here i have an issue controlling the button visibility.

 

I applied this formula on button visibility which i created in reorder screen to accept the new request.

Today()>=NextPurchaseDate

But problem with this formula it is taking the latest Nextpurchase date but it should pull the next purchase date from the latest record of the user and compare it with today.

 

Please let me know how can i achieve this.

Chiranth1992_0-1595266363454.png

Thanks,

CL

 

I'm unclear on how you are calculating these figures. I saw the field in your list called NextPurchaseDate, and assumed you were using that to hold the next date someone could purchase. If that is not the case, you will have to figure out how to derive the date. You can Set a variable in the OnSelect of the gallery to one of the fields in that record and then add time to see how it compares to today and use that to determine whether the button is Disabled or not. Make sure the data you are using in your SP list is accurate, or your testing may not show correct results

@BrianS  Thank you. I was able to achieve what i wanted to do.

Thanks for the help. 

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.

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,891)