The logic was working fine on DEV as we had deactivated the business rule. However, after deploying to TEST and UAT, it stopped working.
While debugging the code as well using browser console, we checked that the break point was hitting the code block where we were setting the value of 2 other fields.
After struggling for few minutes, it came to our mind that Business rule was also written which should have been deactivated.
The business rule was basically clearing the values of the 2 fields if the selected value of field was not in the condition anywhere.
After deactivating the business rule, closing the form, opening it again when we tested it, it worked.
Hope it helps !!