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

Change Form Mode depending on Choice Value in a SharePoint List

Hello everyone,

 

Simple question... (probably)

How do I change the form mode of my custom power apps form in SharePoint depending on the value inside of a choice column?

 

Scenario:

I have a "Status" column with multiple choices.

If the status is "Rejected" and the user tries to Edit the list item, I want the form to be disabled (or Form.View). 

 

If the status is anything else, the user may edit the list item with the enabled form (Form.Edit). 

 

I have tried this so far in the OnEdit property of SharePointIntegration:

If(Choices(Status.Value)="Pending Approval",FormMode.Edit, FormMode.View)

 

Thank you!

2 ACCEPTED SOLUTIONS

Accepted Solutions
RandyHayes
Super User
Super User

@MCFCity 

Your formula will be returning a value of either Edit or View to the OnEdit action behavior.  This will mean/do nothing!

 

Also, you are using a Choices function (which returns a table) and trying to compare that to a text string...you should be getting an error!

 

Please consider changing your Formula to the following:

If("Pending Approval" in SharePointIntegration.Selected.Status.Value, 
    EditForm(SharePointForm1), 
    ViewForm(SharePointForm1)
)

 

I hope this is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

View solution in original post

RandyHayes
Super User
Super User

@MCFCity 

Yes, don't look at PowerApps as "development" - it is not.  It is a no-code platform.  It is modeled after Excel.  So, think formulas and cells.  

The added advantage of PowerApps is that it provides behavioral actions (OnEdit, OnSelect, OnSuccess...etc.) These can be used to perform particular actions.  

 

So, in the case provided, we used two behavioral functions - ViewForm and EditForm to specifically set the state of the form.

 

Had you wanted to actually provide the FormMode.View and FormMode.Edit to something, it would not be a behavioral formula...it would be the DefaultMode property of the form.  And, just like Excel where you do not "set" a cell value from another, but instead put a formula in the cell you want to have a certain value - the same holds true in this case - you would put a formula on the DefaultMode property.

In that case it would have been such a formula:

If("Pending Approval" in SharePointIntegration.Selected.Status.Value, 
    FormMode.Edit, 
    FormMode.View
)

 

But, it was just as easy to do it all in the behavioral action OnEdit.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

View solution in original post

4 REPLIES 4
RandyHayes
Super User
Super User

@MCFCity 

Your formula will be returning a value of either Edit or View to the OnEdit action behavior.  This will mean/do nothing!

 

Also, you are using a Choices function (which returns a table) and trying to compare that to a text string...you should be getting an error!

 

Please consider changing your Formula to the following:

If("Pending Approval" in SharePointIntegration.Selected.Status.Value, 
    EditForm(SharePointForm1), 
    ViewForm(SharePointForm1)
)

 

I hope this is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

Thank you, it works! 🙂

 

I am very new to Power Apps and I already thought that I was probably doing something very wrong. 

RandyHayes
Super User
Super User

@MCFCity 

Yes, don't look at PowerApps as "development" - it is not.  It is a no-code platform.  It is modeled after Excel.  So, think formulas and cells.  

The added advantage of PowerApps is that it provides behavioral actions (OnEdit, OnSelect, OnSuccess...etc.) These can be used to perform particular actions.  

 

So, in the case provided, we used two behavioral functions - ViewForm and EditForm to specifically set the state of the form.

 

Had you wanted to actually provide the FormMode.View and FormMode.Edit to something, it would not be a behavioral formula...it would be the DefaultMode property of the form.  And, just like Excel where you do not "set" a cell value from another, but instead put a formula in the cell you want to have a certain value - the same holds true in this case - you would put a formula on the DefaultMode property.

In that case it would have been such a formula:

If("Pending Approval" in SharePointIntegration.Selected.Status.Value, 
    FormMode.Edit, 
    FormMode.View
)

 

But, it was just as easy to do it all in the behavioral action OnEdit.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

Wow! Great explanation, thank you!

 

This solution is even better as the other one was not as responsive as I would have liked. This one is instant. 

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 (5,064)