I had a task recently to reduce down the number of statuses on an entity, basically taking it down from 20 to 10.
As Adam pointed out in the comments, I am referring to Status Reason = statuscode. For each Status you can have a number of Status Reasons e.g. Active status can have lots of status reasons such as New, Modified etc.
There isn’t any dependency checks in CRM, you can delete statuses even if there are records with that status.
The consultant was suggesting we deactivate the status reason, erm no, you can’t do this either. You could change the status reason to
DO NOT USE – Old Status
This is ok and offers you an easy way to move these options later and stopping (although not always) users from selecting the soon to be deleted status reasons. Personally I don’t really like it because it looks messy and seems like it may lead to more problems later.
If you are going to remove the status reasons then you need to map the old status reason to the new status reasons BEFORE you delete the status reasons. if you don’t then the user will open up the record with the deleted status reason, it will try to look up the int for the status reason, can’t find and then show the default status reason for that status.
What happened was I forgot to map the status reasons across and then I ended up with lots of status reasons which no longer existed. A curious thing happens, the int value is still held in the database. When you open a record which has the old status reasons, on the onload of the form it will change to the default optionset status reason but this will only write back if you save the record.
So lets say I have four statuses
Waiting for user
They get rid of one so we are left with three statuses
With User (renamed Waiting for user)
If you forgot to set the values of the old status reasons to new ones e.g. all the records with a user replied status reason and set it to With User then these records will have the int value for the previous optionset.
The renamed status reason is fine because the int value is the same, when you go to the forms you will see the renamed status reason
How to Fix it
To fix the problem, I did an SQL query on the database table holding the records. I selected all the records and got the name and statuscode value and only for rows with the old optionset value. I then did an advanced find in CRM and selected all the records which didn’t have a status reason for the three left.
I now had the records with dodgy status reasons. I exported the list and ticked the re-import check-box. I then sorted the rows so they were the same to make sure I had the right records. I then updated the status reason with the correct option and re imported.
The morale of the story is be careful when you are deleting status reasons and make sure you have mapped them before you delete any statuses.