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
Super User
Super User

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
Super User
Super User

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

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Carousel_PP_768x460_Wave2 (1).png

2022 Release Wave 2 Plan

Power Platform release plan for the 2022 release wave 2 describes all new features releasing from October 2022 through March 2023.

365 EduCon 768x460.png

Microsoft 365 EduCon

Join us for two optional days of workshops and a 3-day conference, you can choose from over 130 sessions in multiple tracks and 25 workshops.

Top Solution Authors
Users online (3,161)