kenticokentico-12

Kentico - Unable to find a custom user column


I just took over a project from a developer who has already left an organisation and I'm doing some maintenance work in the project. I can see the following code in a custom web part

CurrentUserInfo CurrentUser = MembershipContext.AuthenticatedUser;
DateTime ExpirationDate = CurrentUser.GetValue("aps_expirationdate", DateTime.Now);

The strange thing is, I cannot seem to find this custom field 'aps_expirationdate' anywhere in the system or in the database.

I checked the following places but couldn't find it.

but I cannot seem to find this column anywhere and the other strange thing is, when I debug the code it does return a date value. No bugs in the code so, cannot say that this is an invalid column name. Where else should I look?


Solution

  • Based on what you've put in your initial question, it sounds as if the column was added manually and not through the Kentico UI. In order for the data access layer or the Kentico API to know that field exists, the definition has to be stored within the Kentico module class and not just in the database.

    Here's what I'd do to correct this:

    1. Find what table the field exists in. If you want the custom field to be part of the User or User Settings objects then they need to be added to either the CMS_User or CMS_UserSetting table.
    2. If the field does not exist in either the CMS_User or CMS_UserSetting table, then go to the Modules app in the Kentico UI.
    3. In the Modules App, go to Membership > Classes > Users > Fields and add the aps_expirationdate field.
    4. If you have data in the field aps_expirationdate in the other table, write a query to copy it from the other table to the CMS_User table.
    5. Now the API call as noted above will work.

    If the field is already in the CMS_User or CMS_UserSetting table, then you will have to do the following:

    1. In SSMS, rename that field to aps_expirationdate_old.
    2. In the Modules App, go to Membership > Classes > Users > Fields and add the aps_expirationdate field.
    3. Assuming you have data in the aps_expirationdate_old field in the CMS_User or CMS_UserSetting table, write a query to copy it from the other table to the CMS_User table.

    Your last bullet point states you "Did a manual Sql Search in the database to find a table with a column name 'aps_expirationdate'". This contradicts what you state at the end of your question which states "I cannot seem to find this column anywhere". If you cannot find what table the aps_expirationdate exists in, then check out the following SO answer to find that column in a given database.

    https://stackoverflow.com/a/4849704/698678