Reset selected value in the dropdown on a bootstrap modal

I have a jQuery datatable with click of the row opens a bootstrap modal. When I try to reset the selections for the select2 dropdowns on the modal I see an inconsistent behavior, it works for 2-3 times and then it starts selecting last value in the dropdown. I am using this code before showing the modal.

Any idea what could be the issue? I am using 4.0.13