Integration bus UserInfo - unable to load user settings via API

Tom Troughton asked on December 15, 2015 16:39

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 :(

Correct Answer

Zach Perry answered on December 15, 2015 16:44

You try getting the user info using the provider? var user = UserInfoProvider.GetUserInfo(userName); or var user = UserInfoProvider.GetUserInfo(userId);

That should have the settings. Then you can update the user using the provider too UserInfoProvider.SetUserInfo(user);

1 votesVote for this answer Unmark Correct answer

Recent Answers


Brenden Kehren answered on December 15, 2015 16:50

Then get the UserSettingsInfo based off of the UserID then. There are some weird pieces with the integration bus which don't always work as you'd expect because of the Async nature of the process.

var settings = UserSettingsInfoProvider.GetUserSettingsInfoByUser(user.UserID);

1 votesVote for this answer Mark as a Correct answer

Tom Troughton answered on December 17, 2015 13:13

Thanks guys, yes you're right I needed to load the user data fresh rather than rely on the object passed by the integration connector. Appreciate your advice.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.