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

Setting and Saving value to a ComboBox based on selected item of another ComboBox in EditForm

Hi Everyone, 

 

I want to update a value of a ComboBox(CB1) based on the selected value of the another ComboBox(CB2)in the EditForm. 

 

I have the CB1 ComboBox (It holds the ProductID) in the default DataCard created by the EditForm. I have added a custom DataCard which has the CB2 ComboBox (It holds the ProductName)

So when I select the ProductName in CB2, I want to update the ID in the CB1 ComboBox through code.

 

I have used the below code in the DefaultSelectedItems property of CB1 which updates the ProductID in the CB1.  For testing purpose, I have just checked whether particular item num is present and then assigned its ProductID to the CB1.  I have populated the Items for CB1 as Choices([@Product_Suites].ProductID). So the assigning value type is also same as the items populated in the CB1. Products and Product_Suites are lists in the SharePoint.

 

 

If(
    CB2.Selected.Title in Products.Title,
    {
        Value: LookUp(Product_Suites, ItemNumber = 55555, ProductID)
    },
    Parent.Default
)

 

 

When I add a new item, the ProductID is updated correctly in the view as when I select a ProductName. But the issue is that when I click the Save button which just invokes the SubmitForm function, the new item is not getting saved and showing error on the top as below for the 1st time. When I click Save again it just stays on the same screen:

Update:

Maybe this error is because the ProductID field is a Required field in the SharePoint list. Hence maybe the error. If it is Not a Required field then I guess, the field is saved as Empty instead of the value that is getting set from the above code snippet.


Error on 1st time
:

"An error occurred on the server. Server Response: Product_Suites failed. BadGateway" 

 

However, then when I unselect and select the ProductID manually using my mouse, then the new item is getting saved correctly. I don't know whether I am missing anything here or in their corresponding DataCard. So can anyone please help me out here? 

1 ACCEPTED SOLUTION

Accepted Solutions
StalinPonnusamy
Community Champion
Community Champion

Hi @sgokul95 

 

Set the DefaultselectedItems property of CB1 to

If(IsBlank(CB2.Selected.Title),Parent.Default,
{
        Value: LookUp(Product_Suites, ProductName = CB2.Selected.Title, ProductID)
}
)

 

Set the Update property of  CB1 to

CB1.Selected


Thanks,
Stalin - Learn To Illuminate

View solution in original post

1 REPLY 1
StalinPonnusamy
Community Champion
Community Champion

Hi @sgokul95 

 

Set the DefaultselectedItems property of CB1 to

If(IsBlank(CB2.Selected.Title),Parent.Default,
{
        Value: LookUp(Product_Suites, ProductName = CB2.Selected.Title, ProductID)
}
)

 

Set the Update property of  CB1 to

CB1.Selected


Thanks,
Stalin - Learn To Illuminate

View solution in original post

Helpful resources

Announcements
2022 Release Wave 1 760x460.png

2022 Release Wave 1 Plan

Power Platform release plan for the 2022 release wave 1 describes all new features releasing from April 2022 through September 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,575)