Skip to main content

Notifications

Power Apps - Building Power Apps
Answered

Lookup Field Default Value Error

Posted on by 704

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. 

Categories:
  • Verified answer
    Jeff_Thorpe Profile Picture
    Jeff_Thorpe 6,094 on at
    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
    }
  • aprildunnam Profile Picture
    aprildunnam 704 on at
    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.  

  • v-micsh-msft Profile Picture
    v-micsh-msft on at
    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

     

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

November 2024 Newsletter…

November 2024 Community Newsletter…

Community Update Oct 28…

Power Platform Community Update…

Tuesday Tip #7 Community Profile Tips…

Welcome to a brand new series, Tuesday Tips…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 143,487

#2
RandyHayes Profile Picture

RandyHayes 76,308

#3
Pstork1 Profile Picture

Pstork1 64,014

Leaderboard