FIx orphaned accounts after deleting a user (or how to convert a number to long)
[Update] I downloaded the database and made the changes directly through SQL because I had to get it done right away. [/Update] We deleted some old users from our Mendix application and it broke our OData published service. The error we are getting is that the changedBy field on our entity is pointing to a system.user that no longer exists. I did not think that the Mendix framework would allow this; however, it has and I need to get it fixed. My thought was to use a Retrieve Object activity and an XPAth contsraint of [ActivityTracker.Activity_Account = 5066549680791009]. This gives me an error of “Incompatible expression types: Administration.Acount, Integer.Long.” I thought the Activity_Account which is a relationship was stored as long. Anyone have any idea how I can fix this? I was going to retrieve all the affected objects and then update them to have a user id that is valid. It looks like Mendix 8 has the CAST function but we’re still on 7.16. $DeadUserID is from a Create Integer/Long variable activity.
Instead of having to change the ID to another user, could you do the following:
add a field to the DataEntity object named ODataPublishedChangedBy
Add an on-commit event for DataEntity that retrieves the account of the current user and populates that field with the name of the current user
Add a startup event that retrieves all DataEntities, loops through, retrieves the system.user from the ChangedBy association, and populate the ODataPublishedChangedBy. You can add error handling/conditional logic so that if you try to retrieve a system user that does not exist, it will skip and populate the value for ODataPublishedChangedBy with ‘empty’ or ‘deleted’ or something similar
I know this isn’t ideal, but this will allow you to remove the ‘changedby’ association from your OData published resource and still let you push the relevant data out in the OData feed. That way if another account gets deleted in the future, you won’t have to go through this trouble all over again.