I have created a form in power apps and data is connected with sharepoint list. I would like to restrict the user to submit only 2 entries per user. can someone help me please.
Solved! Go to Solution.
Hi @ameenkvy
You can handle individual controls by adding some logic as follows.
To disable the submit button by adding the following to the displaymode of the submit button.
If(
CountRows(Filter(YourListNAME, User().Email='Created By'.Email)) > 2 , DisplayMode.Disabled, DisplayMode.Edit
)
You could also add a label with red text beside the button to inform the user why it is locked down and set it's visible property to
CountRows(Filter(YourListNAME, User().Email='Created By'.Email)) > 2
Lastly, you could control the mode of the form using the same rationale as the displaymode on button above - so in the Form 'DefaultMode' add:
If(
CountRows(Filter(YourListNAME, User().Email='Created By'.Email)) > 2 , FormMode.View, FormMode.Edit
)
---------------------
If you wanted to apply this rationale in bulk in a more efficient fashion, you could set a variable in the onVisible property of the screen and then just use that variable as the check:
OnVisible of screen:
If(
CountRows(Filter(YourListNAME, User().Email='Created By'.Email)) > 2, UpdateContext({varlRecordCountMet: true})
)
Disable the submit button by adding the following to the displaymode of the submit button.
If(
varlRecordCountMet , DisplayMode.Disabled, DisplayMode.Edit
)
You could also add a label with red text beside the button to inform the user why it is locked down and set it's visible property to
varlRecordCountMet
Lastly, you could control the mode of the form using the same rationale as the displaymode on button above - so in the Form 'DefaultMode' add:
If(
varlRecordCountMet, FormMode.View, FormMode.Edit
)
Hope this helps
Gerard
Hello,
Please create collection on form load after count items from newly collection if grater then 2 then disabled submit button.
Collect (currentUserCollection, Filter(SPListDatasource,AuthorEmail.Email=User().Email))
if(CountRows(currentUserCollection) > 2, "buttonDisabled', "buttonEbabled"))
Hi @ameenkvy
You can handle individual controls by adding some logic as follows.
To disable the submit button by adding the following to the displaymode of the submit button.
If(
CountRows(Filter(YourListNAME, User().Email='Created By'.Email)) > 2 , DisplayMode.Disabled, DisplayMode.Edit
)
You could also add a label with red text beside the button to inform the user why it is locked down and set it's visible property to
CountRows(Filter(YourListNAME, User().Email='Created By'.Email)) > 2
Lastly, you could control the mode of the form using the same rationale as the displaymode on button above - so in the Form 'DefaultMode' add:
If(
CountRows(Filter(YourListNAME, User().Email='Created By'.Email)) > 2 , FormMode.View, FormMode.Edit
)
---------------------
If you wanted to apply this rationale in bulk in a more efficient fashion, you could set a variable in the onVisible property of the screen and then just use that variable as the check:
OnVisible of screen:
If(
CountRows(Filter(YourListNAME, User().Email='Created By'.Email)) > 2, UpdateContext({varlRecordCountMet: true})
)
Disable the submit button by adding the following to the displaymode of the submit button.
If(
varlRecordCountMet , DisplayMode.Disabled, DisplayMode.Edit
)
You could also add a label with red text beside the button to inform the user why it is locked down and set it's visible property to
varlRecordCountMet
Lastly, you could control the mode of the form using the same rationale as the displaymode on button above - so in the Form 'DefaultMode' add:
If(
varlRecordCountMet, FormMode.View, FormMode.Edit
)
Hope this helps
Gerard
@AmDev Thank you. Its working and same time, im getting below warning messages. Also when displaymode is disabled, would like to show the textbox by mentioning the reason why we locked. Could you please help me with both questions. I can see you have already answered for my second question and unfortunately it wasnt clear for me and requesting you elaborate in detail.
@ameenkvy don't worry about the delegation warning. You are getting this because CountRows is not delegable, but this wont be an issue for you as the filter nested inside the countrows is delegable and it will only ever return a max of 2 rows, given the limit you are setting with your form functionality.
In terms of your explanation label, you want that to be visible when users have hit their limit, so you want to add logic into the 'visible' property that will resolve to 'true' under those conditions I.e. displaying the label. You can use the logic I provided above or you could also use the displaymode of your form by usi g the following logic
YourFormName.Mode = Formmode.View
...when your form is in view mode, the label will show.
Note I've realised a mistake in the logic above where it will allow users to add a 3rd record, so instead of '>2' use '=2'.
Hope this helps
Gerard
Firstly @AmDev 's solution is correct and you should accept this - I will just add a small hint if you do not like Delegation warnings (like me)
With(
{
wList:
Filter(
YourListNAME,
'Created By'.Email = User().Email
)
},
If(
CountRows(wList) > 2,
DisplayMode.Disabled,
DisplayMode.Edit
)
)
User | Count |
---|---|
253 | |
113 | |
92 | |
48 | |
38 |