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

DefaultMode in a canvas app form

Hi

 

I have an app in which the user can choose either to "add feature" or to "edit existing feature", like shown below:

OnSelect property of "Add feature:

Set(g_featID,Blank());
Navigate(Screen2,ScreenTransition.None)

 

OnSelect property of "Edit Feature"

Set(g_featID,TextInput1.Text);
Navigate(Screen2,ScreenTransition.None)

 

 main page.PNG

 

 

Upon click, I wanted to use the same canvas-form for the two cases as:

  • for "Add feature" the form should be in FormMode.New
  • for "edit feature" the form should be in FormMode.Edit

So in the next screen, i implemented like this:

OnVisible property of Screen:

If (IsBlank(g_featID), UpdateContext({l_featMode : "Add"}), UpdateContext({l_featMode : "Edit"}));
UpdateContext({l_status : Blank()});
Refresh(TblFeatures)

 

Properties of the form on this screen:

DefaultMode: Switch(l_featMode, "Add", FormMode.New, "Edit", FormMode.Edit)

Item: If (Not(IsBlank(g_featID)),  LookUp(TblFeatures, FeatureID=g_featID))

 

With this, I get correct behaviour if I add one feature:

 

Add feature form

 

add feature_1.PNG

 

add_feature_2.PNG

 

Edit feature form:

edit_feature.PNG

 

 

 

 

But now, if I try to add another record by clicking on "add feature", the form is stuck as "No item to Display":

 

add_feature_3.PNG

Note that the first record is added successfully as can also be seen in the excel table.

 

 

To me, it looks like a bug!

 

 Will appreciate any support/workaround in this issue.

 

(unfortunately, I cant export and share app package due to corporate restrictions)

 

Thanks.

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Super User III
Super User III

Re: DefaultMode in a canvas app form

@saurm,

I think you made it much more complicated than it needs to be.  Powerapps forms usually reference a datatable or a gallery. So normally there is a Datatable or Gallery on the first screen.  Forms can either create a record in a datasource, edit one already created or view one (read only).  You set the default Form mode using the functions EditForm(Form1), NewForm(Form1) and ViewForm(Form1) before you navigate to the second screen containing the Form. So if the form is on a different screen, you could set up your buttons on your first screen, say Add, Edit .  The Add button OnSelect property would be NewForm(Form1),  Navigate(Screen2,ScreenTransition.None), The Edit button would be EditForm(Form1),Navigate(Screen2,ScreenTransition.None) Putting the edit button inside the gallery will automatically select the record to edit.  The Add button can be outside the gallery because a new form is being created.  

On the 2nd screen, there would be an Edit form control.  Its Datasource property would be the same as the datasource of the gallery or datatable.  Its Item property would be Gallery1.Selected.  (The Item property is ignored if the form is in New mode).  On the second screen, You would have a button for Submitting the form with the OnSelect property SubmitForm(Form1) in the picture below it is the check mark.  The X icon OnSelect property would be ResetForm(Form1);Back(None). so you could go back if you decided not to edit the record.  In the OnSuccess property of the form you could put Back(None) and after submitting your property, the app would navigate back to the first screen and your new  or edited item would be displayed in the gallery or datatable.  I hope this helps.  In the example below, I edited Adrian's record by adding Unknown in the Status box.  After clicking the check mark, The form navigated back to the Gallery screen and the new status is shown.

Screen 1Screen 1After clicking edit on AdrianAfter clicking edit on AdrianAfter saving Adrians status as UnknonwAfter saving Adrians status as Unknonw

 

 

View solution in original post

6 REPLIES 6
Highlighted
Super User III
Super User III

Re: DefaultMode in a canvas app form

@saurm,

I think you made it much more complicated than it needs to be.  Powerapps forms usually reference a datatable or a gallery. So normally there is a Datatable or Gallery on the first screen.  Forms can either create a record in a datasource, edit one already created or view one (read only).  You set the default Form mode using the functions EditForm(Form1), NewForm(Form1) and ViewForm(Form1) before you navigate to the second screen containing the Form. So if the form is on a different screen, you could set up your buttons on your first screen, say Add, Edit .  The Add button OnSelect property would be NewForm(Form1),  Navigate(Screen2,ScreenTransition.None), The Edit button would be EditForm(Form1),Navigate(Screen2,ScreenTransition.None) Putting the edit button inside the gallery will automatically select the record to edit.  The Add button can be outside the gallery because a new form is being created.  

On the 2nd screen, there would be an Edit form control.  Its Datasource property would be the same as the datasource of the gallery or datatable.  Its Item property would be Gallery1.Selected.  (The Item property is ignored if the form is in New mode).  On the second screen, You would have a button for Submitting the form with the OnSelect property SubmitForm(Form1) in the picture below it is the check mark.  The X icon OnSelect property would be ResetForm(Form1);Back(None). so you could go back if you decided not to edit the record.  In the OnSuccess property of the form you could put Back(None) and after submitting your property, the app would navigate back to the first screen and your new  or edited item would be displayed in the gallery or datatable.  I hope this helps.  In the example below, I edited Adrian's record by adding Unknown in the Status box.  After clicking the check mark, The form navigated back to the Gallery screen and the new status is shown.

Screen 1Screen 1After clicking edit on AdrianAfter clicking edit on AdrianAfter saving Adrians status as UnknonwAfter saving Adrians status as Unknonw

 

 

View solution in original post

Highlighted
Kudo Collector
Kudo Collector

Re: DefaultMode in a canvas app form

Hi @saurm

actually @Drrickryp, was right about about complicating simple things!

since PowerApps started using DisplayMode property i started using only a single form for both editing and viewing.

so here's what i suggest you do:

  1.  go to insert>form>edit to insert your editform.
  2. it is best practice to always link the form.item property to a gallery.selected or data table, or even dropdown or combo box.
  3. change the form.DefaultMode property to FormMode.View
  4. change the form.OnSuccess property to: ViewForm(FormName)
  5. Change the form.OnReset property to: ViewForm(FormName)
  6. OnSelect property of "Add feature: NewForm(FormName);Navigate(Screen2,Transition.none)
  7. OnSelect property of "Edit feature: EditForm(FormName);Navigate(Screen2,Transition.none)
  8. OnSelect property of the Check icon: SubmitForm(FormName);Navigate(Screen1,Transition.none)

try it out and let me know if it is successfull.

 

regards,

Mohammad

Highlighted
Frequent Visitor

Re: DefaultMode in a canvas app form

@Drrickryp, Thanks for introducing me to EditForm, NewForm and ViewForm functions.

and saving me from extra complexity - appreciate it.

Highlighted
Frequent Visitor

Re: DefaultMode in a canvas app form

@mokhawaja The step 4 shared by you was quite useful to improve my actual app's behavior...

Thanks for step by step details

 

Highlighted
Kudo Collector
Kudo Collector

Re: DefaultMode in a canvas app form

thanks @saurm, glad you solved your issue!!

Highlighted
Post Patron
Post Patron

Re: DefaultMode in a canvas app form

I was totally stumped on this one!  Finally came across this post. 

 

I'd had Select(Parent) where I should have had ViewForm(frmRequest_1).  No matter what I did, my form was always in Edit mode when I selected it from the gallery.  When I used ViewForm...it took care of things!   Thanks ever and ever so much!  

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

Watch Now

Experience what’s next for Power Apps

See the latest Power Apps innovations, updates, and demos from the Microsoft Business Applications Launch Event.

Power Platform ISV Studio

Power Platform ISV Studio

ISV Studio is designed to become the go-to Power Platform destination for ISV’s to monitor & manage published applications.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors
Users online (5,704)