cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Marini83
Frequent Visitor

Patch causes dropdown list to default to the first item not item it was on before patch executed.

Having a bit of a problem. I have a button when pressed, It uses Patch to make an update to the database. All is great. However what happens the drop down defaults to the first item. The rest of the textfields remain the same. It's just the dropdown that is causing this. I have tried using UpdateContext but it always defaults to the first item. Namely I am showing the Project Name, the item contains a few more fields.  I generate the items for a SQL Server LookUp initially. 

1 ACCEPTED SOLUTION

Accepted Solutions

Hi @Marini83 ,

Please consider modify above formula as below:

Set the Default property of the DropdownProject Box to following:

LookUp('[dbo].[Projects]', ProjectCode = selectedProjectCode, ProjectName)

Or

LookUp('[dbo].[Projects]', ProjectCode = selectedProjectCode).ProjectName

 

then check if the issue is solved.

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

6 REPLIES 6
v-xida-msft
Community Support
Community Support

Hi @Marini83 ,

Could you please share a bit more about your issue?

Could you please show more details about the Patch formula you used within your app?

Does the Dropdown box connect to the data source you want to update using your Patch function?

Further, do you reset the Dropdown box after your Patch formula?

 

Based on the issue that you mentioned, I have made a test on my side, and don't have the issue that you mentioned. When I use Patch function to submit my form data, the Dropdown box/ComboBox would remain the same.

If the Dropdown box connect to the data source you want to update using your Patch function, I think this is the issue. When you use Patch function to update the data source, the data source within your app would be refreshed, so the Dropdown box which connects to the data source would also be refreshed/reset.

 

Please also check if you have add Reset() formula within your app to reset your Dropdown box.

 

As an alternative solution, please consider take a try with the following workaround:

Set the OnChange property of the Dropdown box to following formula:

Set(CurrentSelectedOption, DropdownBox.Selected.Value)

Set the Default property of the Dropdown box to following:

CurrentSelectedOption

 

If the Dropdown box that you mentioned is actually a ComboBox control, please take a try with the following workaround:

Set the OnChange property of the Dropdown box (ComboBox) to following formula:

Set(CurrentSelectedOption, DropdownBox.Selected.Value)

Set the DefaultSelectedItems property of the Dropdown box to following:

{
Value: CurrentSelectedOption
}

 

Please consider take a try with above solution, then check if the issue is solved on your side.

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Reset is set to false. 
This is what I have on OnChange. The Patch function is being triggered by a button, not the dropdown itself. I'm also attaching code for the submit button. 

UpdateContext({msg: "Executing Patch"});
UpdateContext(
    {
        patchResult: Patch(
            '[dbo].[Projects]',
            First (
                Filter (
                    '[dbo].[Projects]',
                    ProjectCode = selectedProject.ProjectCode
                )
            ),
            {ProjectName: NameTextField.Text,ProjectAlias: AliasTextField.Text, Client: ClientTextField.Text, ProjectStartDate: StartDateDatePicker.SelectedDate, 
            ProjectEndDate: EndDateDatePicker.SelectedDate}
        )
    }
);

UpdateContext({selectedProjectCode : selectedProject.ProjectCode });

UpdateContext(
    {
        msg: If(
            Not(IsBlank(patchResult)) And IsEmpty(Errors('[dbo].[Projects]')),
            "Patch succeeded",
            "Patch failed"
        )
    }
);

UpdateContext(
    {
        updateVisible: If(
            Not(IsBlank(patchResult)) And IsEmpty(Errors('[dbo].[Projects]')),
            false,
            true
        )
    }
);

UpdateContext(
    {
        updateDisplayMode: If(
            Not(IsBlank(patchResult)) And IsEmpty(Errors('[dbo].[Projects]')),
            DisplayMode.View,
            DisplayMode.Edit
        )
    }
);

Refresh('[dbo].[Projects]')

Hi @Marini83 ,

Have you taken a try with the alternative solution I provided above?

 

Based on the screenshot that you provided, I think this issue is related to the data source ('[dbo].[Projects]') your Dropdown box (DropdownProject) related to.

When your "Submit" button is pressed, your Patch formula is executed, then your '[dbo].[Projects]' table would be updated. The '[dbo].[Projects]' data source within your app would be refreshed, so the Dropdown box (DropdownProject) connected to the '[dbo].[Projects]' data source would be reset.

 

As an alternative solution, please consider take a try with the following workaround:

Set the OnChange property of your DropdownProject Box to following:

 

UpdateContext({selectedProjectCode : DropdownProject.Selected.ProjectCode});
UpdateContext({selectedProject : LookUp('[dbo].[Projects]', ProjectCode = DropdownProject.Selected.ProjectCode) })

Set the Default property of the DropdownProject Box to following:

LookUp('[dbo].[Projects]', ProjectCode = DropdownProject.Selected.ProjectCode, ProjectName)

Or

LookUp('[dbo].[Projects]', ProjectCode = DropdownProject.Selected.ProjectCode).ProjectName

Please consider take a try with above solution, then check if the issue is solved.

 

Best regards,

 

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi Kris,

 

Thank you for your help. I did try to set the OnChange and default. The issue with default is that when I try one of the methods as mentioned I get the following error:

 

This Rule Creates a Circular Reference,

Hi @Marini83 ,

Please consider modify above formula as below:

Set the Default property of the DropdownProject Box to following:

LookUp('[dbo].[Projects]', ProjectCode = selectedProjectCode, ProjectName)

Or

LookUp('[dbo].[Projects]', ProjectCode = selectedProjectCode).ProjectName

 

then check if the issue is solved.

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Perfect it works now! Thank you 🙂 

Helpful resources

Top Solution Authors
Top Kudoed Authors
Users online (4,022)