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

Can't get default values in lookup field on new form to work

I have several screens on an app.  The first has two galleries:  List A on the left, and when an item is selected, List B on the right displatys items where the lookup field value in it equals the title in list A.  In other words, list B has a lookup fiield back to List A and uses title.  Each gallery uses a collection from OnStart LisA items and ListB items.

 

There is an icon on the screen that when selected navigates to a screen with a new form for List B.  I have unlocked the lookup field on that form which is a dropdown list that selects from titles in List A and set the default to be:

 

{  '@odata.type' :
   "#Microsoft.Azure.Conntctors.SharePoint.SPListExpandedReference",
   Id: gaListA.Selected.ID,
   Value: galListA.Selected.Title
}   

 

Where galListA is the gallery on the main screen for List A; List A has items that are a collection creted OnStart from List A: colListA.  WHen I run it the field is still showig Find Items...

 

THe form, however, shows List B as the datasouce and no option to change it to a collection.

 

Several other things I wonder about:

 

  1. On the datacard for the list choices, Items shows Choices(ListB.NameField).  Does this interfere?  I have tried deleting it with no change in results.
  2. If the collection usage for the galleries is screwing things up, should I drop the collections and instead go back to using the SP lists as the datasource?

I get no formula erros on Default nor do I get any exectuion errors, but the field value in the lookup just doesn't get set.  If I try to save the form,. it gives me a required value error, so it is truly not being set.

 

Why does the default funtion work for everyone but not me?

2 ACCEPTED SOLUTIONS

Accepted Solutions
Andy_Tuke
Level 8

Re: Can't get default values in lookup field on new form to work

The app I build in my blog does exactly what you are trying to do as far as I can see. My list A, holds customer details and my list B holds projects.  When I add a new project it sets the lookup column in the project list to the selected customer in the first gallery.  The lookup column in projects is set to return the titles from the customer list.  The form I added defaults to a drop down control when it connects to a lookup field. I simply set it's default property (of the data card not the actual drop down on it) and that was it. 

If you want to upload the msapp file and a description of screenshot of the list settings I can have a look tomorrow probably

Andy

 

Re: Can't get default values in lookup field on new form to work

Problerm solved!  I had put the default value in the defalut property of the actual dropdown in the lookup field instead of the whole data card property.   I finally spotted this on your blog post.  

 

A silly and stupid error on my part and easy enough to fix.

12 REPLIES 12
Andy_Tuke
Level 8

Re: Can't get default values in lookup field on new form to work

Are you sure your collection is populated when you test it.  The OnStart doesnt appear to run when you preview from the editor, its worth checking the View/Collections screen to see if there is data there.

Initially your code looks good, but I have written a couple of blog posts this week (link below) about lookup columns which might help spot where its got something wrong.

If you need some more helpd with this feel free to contact me.

 

regards

Andy
Read my new blog at -
www.powerappssolution.com

Madi
Level: Powered On

Re: Can't get default values in lookup field on new form to work

even not working for me Smiley Sad 

Andy_Tuke
Level 8

Re: Can't get default values in lookup field on new form to work

Not usre I follow that reply?

Is your collection defintely populated with some data?

Re: Can't get default values in lookup field on new form to work

yes, collections are populated (for tesing I have a button that executes OnStart functions.  I also put a label on the form that grabs gal.client.title.value and it displays correctly.  That doesn't work for the lookup field because it wants record not text value. And yes, i can see them in View->collections and they show up in the galleries.  What doesn't show up is any value in the dropdown field where I set the default value.

 

 

Re: Can't get default values in lookup field on new form to work

Does your post mean you are having the same problem?

Re: Can't get default values in lookup field on new form to work

I read your most recent blog post, and what is different in my app is that the lookup field is NOT a drop down control but a SharePoint list lookup field; specifially in List B there is a lookup field referencing Title in List A.  it is that field, on the edit form for List B, that I want to set to a value from the List A selected item on the gallery for List A, when adding a new List B item.  As I just posted, if I add a label to the edit form where its value is galListA.Selected.Title.Value, it works as I want.  Using the odata values in my original post as the default value for this lookup field do not work at all.  No formula error nor execution error, just no result.  It's as though it cannot resolve the ID and returns nothing, although in actuality it may be something else.

Re: Can't get default values in lookup field on new form to work

I just did a small app to test whether or not collecitons might be a factor.  I created a gallery on a screen that used list A, and then a form on the same screen using List B but in displaymode.new.  I set the odata value to point to the selected item in List A, set templatefill in List A to highlight the row in gallery so I know for certain one was selected, but the default value in the lookup field not not change to the title of that item in List A but remained as Find Items and the dropdown worked to show the values.  If i remoeved the Choice(listb.name) then no drop down choices appear.

 

 

Andy_Tuke
Level 8

Re: Can't get default values in lookup field on new form to work

The app I build in my blog does exactly what you are trying to do as far as I can see. My list A, holds customer details and my list B holds projects.  When I add a new project it sets the lookup column in the project list to the selected customer in the first gallery.  The lookup column in projects is set to return the titles from the customer list.  The form I added defaults to a drop down control when it connects to a lookup field. I simply set it's default property (of the data card not the actual drop down on it) and that was it. 

If you want to upload the msapp file and a description of screenshot of the list settings I can have a look tomorrow probably

Andy

 

Re: Can't get default values in lookup field on new form to work

Problerm solved!  I had put the default value in the defalut property of the actual dropdown in the lookup field instead of the whole data card property.   I finally spotted this on your blog post.  

 

A silly and stupid error on my part and easy enough to fix.

Helpful resources

Announcements
firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

SecondImage

PowerApps Monthly Community Call

Next Wednesday, August 21st at 8am PDT

Top Community Contributors for July 2019

Top Community Contributors for July 2019

Let's thank our top community contributors

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

FirstImage

Power Platform World Tour

Coming to a city near you

thirdimage

PowerApps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

FourthImage

Join PowerApps User Group!!

Connect, share, and learn with your peers year-round

FifthImage

Dynamics 365 and Power Platform April 2019 Release notes

Features releasing from April 2019 through September 2019!

SixthImage

Power Summit Australia 2019

August 20-23rd 2019

Users Online
Currently online: 19 members 4,269 guests
Please welcome our newest community members: