Hi Sam,
I would recommend you to primarily have a check manually via transaction, if that works well, then go about changing the same via code i.e. when we do it manually we can observe what runs in the background(in debugging mode) and also if there are any inconsistencies/ faulty items that can be also ignored when tried to change via program as in your case.
Please validate the same at your end as well, please come back if any further inputs are required.
BR/Thanks
Pranav Agrawal