cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
kev160967
New Member

Fetching specific record on application startup

I'm trying to write an application backed against a sharepoint list. When the application starts I need it to try to find a specific entry in that list and open a form in edit mode against that record. If the record doesn't exist I should instead open the form in new record mode and populate some default values. My record lookup criteria are based on the current user and a date. 

 

I think I can see how to handle most of the flow using OnVisible events on the main form, but I'm drawing a blank on how to use PowerApps to select that initial record. I need to load it into a variable and set the datasource of my edit form to use that variable. If its not set then I can use the new record form instead (using an IF function) with my defaults stored in variables and the relevant fields bound to those variables.

 

So far I've tried the following, which seemed promising but when the form opens it shows as "no datasource provided", despite there being several records with display name "Test  User". I've set the form's datasource to ppStartRecord:

 

Set(ppStartRecord, LookUp(WeeklyActivity, User.DisplayName="Test User"))

 

Any advice on how I can set a variable to a specific sharepoint list entry such that that variable can be the datasource for an edit form would be extremely welcome!

 

Thanks

Kevin

1 ACCEPTED SOLUTION

Accepted Solutions
NandiniBhagya20
Solution Sage
Solution Sage

Hi,
You have to set the datasource property of the form to your list - WeeklyActivity
and item property to - 
Set(ppStartRecord, LookUp(WeeklyActivity, User.DisplayName="Test User"))
or the variable - ppStartRecord
And FormMode property of the form to If(IsBlank(ppStartRecord), ForMode.New, FormMode.Edit)


Did you like my post? Please give it a thumbs up! Did I resolve your issue? Please click Accept as Solution to close the topic and so other members of the community can find solutions more easily.

View solution in original post

4 REPLIES 4
phipps0218
Super User
Super User

You can handle this on app start. Set a variable to lookup a record in your sharepoint list based on the logged-in user then wrap this in an if statement. Depending on the variable, if blank then new form else edit form. Which part do you need help writing?

Please Accept as Solution if it solves your question. Or just give it a Thumbs Up if it is helpful because this can help others.

LinkedIn: https://www.linkedin.com/in/charlie-phipps-%F0%9F%91%A8%E2%80%8D%F0%9F%92%BB-91338715b/
YouTube: https://www.youtube.com/channel/UChmFBGU1YKIU91sNMQ7buGg
Twitter: https://twitter.com/phipps0218

Thanks, I've edited the original post to include what I'm currently trying. For the moment I'm using a static filter in a lookup statement as a proof of concept, but something isn't getting tied together correctly. I'm running the Set/Lookup in the OnVisible handler for my form, and firing this off in preview mode. At the moment  the form is telling me it doesn't have a datasource set. I'm currently experimenting to see if this is due to my Lookup not being called, or it failing in some way

NandiniBhagya20
Solution Sage
Solution Sage

Hi,
You have to set the datasource property of the form to your list - WeeklyActivity
and item property to - 
Set(ppStartRecord, LookUp(WeeklyActivity, User.DisplayName="Test User"))
or the variable - ppStartRecord
And FormMode property of the form to If(IsBlank(ppStartRecord), ForMode.New, FormMode.Edit)


Did you like my post? Please give it a thumbs up! Did I resolve your issue? Please click Accept as Solution to close the topic and so other members of the community can find solutions more easily.

kev160967
New Member

Thanks, that makes sense. I'm now getting a different error (No item to display) but I'll play with for a bit as its likely a fault in my query

Helpful resources

Announcements
Microsoft 365 Conference – December 6-8, 2022

Microsoft 365 Conference – December 6-8, 2022

Join us in Las Vegas to experience community, incredible learning opportunities, and connections that will help grow skills, know-how, and more.

Power Apps Ideas

Check out the New Ideas Site

We are excited to announce a new way to share your ideas for Power Apps!

Top Solution Authors
Top Kudoed Authors
Users online (3,316)