web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / How to set form mode b...
Power Apps
Answered

How to set form mode based on non/existence of record?

(0) ShareShare
ReportReport
Posted on by 32

Hello! I have a table in a data source that has a date column. Any given date may or may not have a row associated with it.

 

Then I have a canvas app with a DatePicker and an associated form, Form1. I want to be able to select an arbitrary date, and if there's already a row in the data source for that date, I want to put the form in view (or potentially edit) mode; if not, I want to put the form in new mode.

 

How can I do this?  Thanks!

 

(One path I've considered is setting an onchange handler on the DatePicker which would look something like "If(Form1.ThisItem, ViewForm(Form1), NewForm(Form1))" but a) ThisItem doesn't seem defined in this context and b) there's no guarantee that the load status would be accurate at control change time.

 

Another that seems more "Power Apps-y" would be to set a property such as Form1.Mode to If(Form1.ThisItem, FormMode.View, FormMode.New) and let the responsive engine do its thing, but I can't seem to find such a property...)

Categories:
I have the same question (0)
  • Verified answer
    cwebb365 Profile Picture
    3,294 Most Valuable Professional on at

    So wherever you are setting the Item property of the form, add a ; after it, then do something like If( IsBlank( "The Item property of the form here" ) , NewForm(Form1), ViewForm(Form1)) 

     

    This basically will set the formMode based on if the item exists or not. 

  • beejo Profile Picture
    32 on at

    So first I confess, my real case is trickier as I have two different fields I am filtering on, so Form1.Item is actually:

    First(
     Filter('Test Table', 'Category' = Category_DropDown.SelectedText.Value, Date = Date_DatePicker.SelectedDate)
    )

     

    However, even if I do the ridiculous thing (bloated, redundant, with race conditions, etc.) and change my Item to:

     

    First(
     Filter('Test Table', 'Category' = Category_DropDown.SelectedText.Value, Date = Date_DatePicker.SelectedDate)
    );
    If(
     IsBlank(
     First(
     Filter('Test Table', 'Category' = Category_DropDown.SelectedText.Value, Date = Date_DatePicker.SelectedDate)
     )
     ),
     NewForm(Form1),
     EditForm(Form1)
    )

     

    ... NewForm() and EditForm() are red-underlined with error "Behavior function in a non-behavior property.  You can't use this property to change values elsewhere in the app."

     

    Am I completely misunderstanding you??

  • cwebb365 Profile Picture
    3,294 Most Valuable Professional on at

    Yeah, you can't set those on the Item property. I was saying use it on one of your events of your pickers, but use the same Filter to compare against to see if it returns a record. The isBlank() (it might need IsEmpty()) can't remember, is just saying if that filter that your Item property would use doesn't return anything, then set the form to NewForm(Form1) , or ViewForm(Form1). 

     

    That's kind of the basic principal. 

  • beejo Profile Picture
    32 on at

    Yeeeeah, I got you.  It does seem to work except for the initial load (since there's no initial change event and I guess I would have to force one), but boy does it feel clunky.  I have to attach it to both pickers (redundant) and I suspect each change is making two requests to the data source, one from Form.Item and one from picker onchange (inefficient) 😞

     

    No offense, maybe that's the best I can get.  Little surprising though, it seems like a pretty common use case.

  • cwebb365 Profile Picture
    3,294 Most Valuable Professional on at

    The only way to set a form mode is by the functions, and those only can be tied to events, so it's kind of the only way. You can set a default, but you have to call a reset each time to load the default logic anyway, I just prefer to handle the app flow manually. 

     

    To handle initial load, you can always add same logic to OnStart, if you have some kind of default record coming in. Or whatever action / event you take to get to the screen with the form. 

  • beejo Profile Picture
    32 on at

    I agree that events are the right place to do it.  I'm just thinking, the platform makes a decision in View mode whether or not to show a record or to display "No item to show" (basically where you would expect an onLoad() handler to be) and that would be the perfect place to attach an event to switch to New mode.  But if that isn't an exposed interface, I'm kinda out of luck for a low-profile solution.

     

    Thanks for the help.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 392 Most Valuable Professional

#2
11manish Profile Picture

11manish 136 Super User 2026 Season 2

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 109 Super User 2026 Season 2

Last 30 days Overall leaderboard