cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
sgokul95
Helper I
Helper I

How to update the LookUp field of a SharePoint list in the Edit Form based on the selection of another ComboBox

Hi All,

 

I have 2 lists named Projects and Product_Suites.

  • The Projects list contain Name, Description and ofcourse an ID column.
  • In the Product_Suites list, I have linked the Projects list columns as LookUp columns. The main LookUp column ProjectID displays the ID of the Projects list (Since its a main lookup column, when clicking an ID of ProjectID lookup column, it will navigate to the corresponding record of the Projects list.

In PowerApps, I have an EditForm for the Product_Suites list.  I have set the DisplayMode of the ProjectID_DataCard as View because the end user won't be able to set the ProjectID as it will display the ID only and not the name.

So, I have added a custom data card (ProjectName_DataCard) in which I have used a ComboBox to display the Project name values. 

 

So when a user selects a Project name in the custom ProjectName_DataCard, I want to update the Selected Item of the ComboBox present in the ProjectID_DataCard. So that when Submiting the form, the ProjectID will be updated in the SharePoint. 

 

Items property of ProjIDComboBox in the ProjectID_DataCard: This code was automatically set when EditForm is created.

Choices([@Product_Suites].ProjectID)

 

Items property of the ComboBox1 in the custom ProjectName_DataCard: The Projects list only contains all the Project names.

Projects.'Name (Title)'

 

I have tried to set the DefaultSelectedItems property of the ComboBox in the ProjectID_DataCard as below code. 

Since the ProjectID is a LookUp column in the SharePoint list and it links to the corresponding record of the Projects list, the return type is of a record, hence I passed the corresponding record in the code that I tried below. 

If(
    ComboBox1.Selected.'Name (Title)' in Projects.'Name (Title)', 
    LookUp(
        Projects,
        'Name (Title)' = ComboBox1.Selected.'Name (Title)'
    ),
    Parent.Default
)

 But the ProjectID is not getting updated in the ProjIDComboBox. 

 

So can anyone let me know how to set the ProjectID based on the selection in the ComboBox1 of the custom ProjectName_DataCard?

1 ACCEPTED SOLUTION

Accepted Solutions

Hi @sgokul95 ,

Lookup columns . . .they will cause you more unnecessary grief than almost any other type (other then Person fields) - I have have not used them for many years - you might be interested in this blog of mine.

I am not sure why you are displaying the ID instead of the field name in the Items, however your Data Card Update will be something like

{
   Value:ComboBox1.Selected.'Name (Title)',
   Id:
   LookUp(
      Projects,
      'Name (Title)' = ComboBox1.Selected.'Name (Title)'
   ).ID
}

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

Visit my blog Practical Power Apps

View solution in original post

3 REPLIES 3
WarrenBelz
Super User
Super User

Hi @sgokul95 ,

DefaultSelectedItems should be (I am assuming a few names here, but you will get the idea of the syntax required)

If(
   ComboBox1.Selected.'Name (Title)' in Projects.'Name (Title)', 
   {
      Value:    
      LookUp(
         Projects,
         'Name (Title)' = ComboBox1.Selected.'Name (Title)'
      ).'Name (Title)'
   },
   {Value:ThsItem.ProjectID}
   )
)

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

Visit my blog Practical Power Apps

 

Hi @WarrenBelz ,

 

Thanks for your quick response. I have tried the suggested code and modified it as below such that the ProjectID is set as the Value instead of the Name.

 

If(
   ComboBox1.Selected.'Name (Title)' in Projects.'Name (Title)', 
   {
      Value:    
      LookUp(
         Projects,
         'Name (Title)' = ComboBox1.Selected.'Name (Title)'
      ).ID
   },
   {Value:ThisItem.ProjectID}
)

 

sgokul95_0-1636691734012.png

 

Now the value is displayed correctly in the ProjectID field. But the thing is that, it is not getting saved in the SharePoint when invoking the SubmitForm function. Here is the Update property of the ProjectID_DataCard. 

 

ProjIDComboBox.Selected

 

Hi @sgokul95 ,

Lookup columns . . .they will cause you more unnecessary grief than almost any other type (other then Person fields) - I have have not used them for many years - you might be interested in this blog of mine.

I am not sure why you are displaying the ID instead of the field name in the Items, however your Data Card Update will be something like

{
   Value:ComboBox1.Selected.'Name (Title)',
   Id:
   LookUp(
      Projects,
      'Name (Title)' = ComboBox1.Selected.'Name (Title)'
   ).ID
}

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

Visit my blog Practical Power Apps

View solution in original post

Helpful resources

Announcements
User Group Leader Meeting January 768x460.png

Calling all User Group Leaders!

Don't miss the User Group Leader meetings on January, 24th & 25th, 2022.

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Top Solution Authors
Top Kudoed Authors
Users online (2,162)