cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
aprildunnam Impactful Individual
Impactful Individual

Lookup Field Default Value Error

Hello.  I'm facing an issue with setting the default value of a Lookup column.  My datasource is a SharePoint list.  I have a parent/child relationship between two lists.  For example, I have a "Projects" list and another "Time" list with a lookup column pointing to the Projects lists so you can put time in for a particular project.  On my New Form  for the Time List in PowerApps I want to auto-populate the Project Lookup column with the currently selected Project that I have as a global variable in PowerApps.  I thought I could do this by setting the Default Value of the Lookup Data Card to this:

{
'@odata.type' : "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",
Id: varWO,
Value: varWO
}

 

It looks like in the Preview it is setting the value correctly, however, when I submit no record is added to the list and I see an error that "A value must be provided for item".  

 

Has anyone else ran into this?  Is this a bug?  This project needs to be done by Friday morning and this is the last thing I have to do to get it done and I'm out of ideas.  I even tried just creating a single line of text field and trying to auto-populate that with my global variable.  That will create a record but with a blank column value. 

1 ACCEPTED SOLUTION

Accepted Solutions
Super User
Super User

Re: Lookup Field Default Value Error

The record you are passing in the default formula is expecting a number for "ID" and string for "Value". You are using the same variable for both "ID" and "Value" because your lookup item ID is also the same as your Title field and I believe this is what is causing your issue. I am assuming your variable is storing the value as a string, so when you use it for "ID" it isn't a valid data type. Try wrapping the Value function around the variable when it is used with "ID" to convert it to a number.

 

Here is an example.

 

{
'@odata.type' : "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",
Id: Value(varWO),
Value: varWO
}


--------------------------------------------------------------------------------
If this post helps answer your question, please click on “Accept as Solution” to help other members find it more quickly. If you thought this post was helpful, please give it a Thumbs Up.

View solution in original post

3 REPLIES 3
Community Support
Community Support

Re: Lookup Field Default Value Error

 

Hi @aprildunnam,

 

What is your current situation?

 

The default value of the lookup should be configured as below:

 

{
'@odata.type' : "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",
Id: 'The corresponding Item ID of the Lookup list item',
Value: 'The value of the Lookup list item'
}

 I suspect the reminder should mention that the Id value is not within the available data range.

Basically, Id field should be the corresponding Item ID of the value you would like to set, and the value property should be set to the data of the lookup field.

The data would be saved successfully only when the Id and the Value matches to the same item of the lookup list item.

 

Regards,

Michael

 

Community Support Team _ Michael Shao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
aprildunnam Impactful Individual
Impactful Individual

Re: Lookup Field Default Value Error

Hello.  I am using the exact configuration you mentioned in the default value of the lookup.  In my SharePoint List the ID and Title are the same value.  I have a global variable in my PowerApp that is getting the ID for the lookup and I'm passing that in the default value logic.  I've verified that the value in my global variable matches the ID and Title of the lookup item in question.  Despite this, I still get the error when submitted.  

Super User
Super User

Re: Lookup Field Default Value Error

The record you are passing in the default formula is expecting a number for "ID" and string for "Value". You are using the same variable for both "ID" and "Value" because your lookup item ID is also the same as your Title field and I believe this is what is causing your issue. I am assuming your variable is storing the value as a string, so when you use it for "ID" it isn't a valid data type. Try wrapping the Value function around the variable when it is used with "ID" to convert it to a number.

 

Here is an example.

 

{
'@odata.type' : "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",
Id: Value(varWO),
Value: varWO
}


--------------------------------------------------------------------------------
If this post helps answer your question, please click on “Accept as Solution” to help other members find it more quickly. If you thought this post was helpful, please give it a Thumbs Up.

View solution in original post

Helpful resources

Announcements
MBAS Gallery 2020

MBAS Gallery 2020

Watch Microsoft Business Applications Summit sessions on-demand.

firstImage

New Ranks and Rank Icons released on April 21!

The time has come: We are finally able to share more details on the brand-new ranks coming to the Power Apps Community!

Top Solution Authors
Top Kudoed Authors
Users online (8,410)