I've added an integration bus connector subscribed to creation of users like this:
SubscribeToObjects(TaskProcessTypeEnum.AsyncSnapshot, PredefinedObjectType.USER, TaskTypeEnum.CreateObject);
My task processor uses the ProcessInternalTaskAsync
override and gets the UserInfo
object as follows:
var user = ((BaseInfo)infoObj) as UserInfo;
When debugging I can examine this object and it does contain my user user's properties. I am now pushing the user data to a CRM then updating the user object with the CRM ID. This ID is a custom field so I am trying to update as follows:
user.UserSettings.SetValue("CrmIDs", value.ToString());
user.UserSettings.Update();
This throws an exception on the second line, saying: [BaseInfo.Update]: Object ID (UserSettingsID) is not set, unable to update this object.
If I examine the object further I can see that user.UserSettings.UserSettingsID
is zero. Furthermore, calling CMS.Membership.UserSettingsInfoProvider.GetUserSettingsInfoByUser(user.UserID)
returns null.
But, if I look in the database I can see that there is a record in [dbo].[CMS_UserSettings]
for this user and if I pass its ID to the API call CMS.Membership.UserSettingsInfoProvider.GetUserSettingsInfo
I get the UserSettingsInfo
object I'm looking for.
So can anyone explain why I'm not able to get the UserSettings object from the user itself? Obviously I don't have access to the ID of the [dbo].[CMS_UserSettings]
record at runtime so right now I have no means to update this object :(