Portal Engine Questions on portal engine and web parts.
Version 7.x > Portal Engine > Problem calling userinfo.update() View modes: 
User avatar
Member
Member
robert-pulldigital - 6/28/2013 5:57:07 AM
   
Problem calling userinfo.update()
Pretty simple and before I dig into it it's probably easier to find out what im failing to do.

We have created an integration bus that will keep CMS Users in sync in a 3rp party database.

We have created an integration class that uses the following line to subscribe to user updates and create a task in the outgoing queue
SubscribeToObjects(TaskProcessTypeEnum.AsyncSimple, PredefinedObjectType.USER);

We have added some simple logic to bypass admin users and any other users we are not interested in synchronizing.

The code for integration currently looks like
if (infoObj.ObjectType == PredefinedObjectType.USER)
{
UserInfo userInfo = infoObj.MainObject as UserInfo;

if (userInfo.IsGlobalAdministrator)
{
result = IntegrationProcessResultEnum.OK;
}
else
{
//CREATE SalesForce Contact and send to sales force
Contact contact = new Contact();
contact.FirstName = userInfo.FirstName;
contact.LastName = userInfo.LastName;
contact.Email = userInfo.Email;
contact.Id = userInfo.GetStringValue("salesforceid", "");

string salesforceid;
if (Connector.GetCurrent().WriteContactToSalesforce(contact, out salesforceid))
{
result = IntegrationProcessResultEnum.OK;
errorMessage = "Process OK";
//if we get an id back it should be saved to the UserInfo
if (!string.IsNullOrEmpty(salesforceid))
{
userInfo.SetValue("salesforceid", salesforceid);
userInfo.Update();
}
}
}

It will not stay like this I am just prototyping and trying to learn the basics.

The call to userInfo.Update which I don't believe should fail throws an exception.
[BaseIntegrationConnector.ProcessInternalTask]: Error processing task. Original message: [DataConnection.HandleError]: Query: UPDATE CMS_UserSettings SET [UserNickName] = @UserNickName, [UserPicture] = @UserPicture, [UserSignature] = @UserSignature, [UserURLReferrer] = @UserURLReferrer, [UserCampaign] = @UserCampaign, [UserMessagingNotificationEmail] = @UserMessagingNotificationEmail, [UserCustomData] = @UserCustomData, [UserRegistrationInfo] = @UserRegistrationInfo, [UserPreferences] = @UserPreferences, [UserActivationDate] = @UserActivationDate, [UserActivatedByUserID] = @UserActivatedByUserID, [UserTimeZoneID] = @UserTimeZoneID, [UserAvatarID] = @UserAvatarID, [UserBadgeID] = @UserBadgeID, [UserShowSplashScreen] = @UserShowSplashScreen, [UserActivityPoints] = @UserActivityPoints, [UserForumPosts] = @UserForumPosts, [UserBlogComments] = @UserBlogComments, [UserGender] = @UserGender, [UserDateOfBirth] = @UserDateOfBirth, [UserMessageBoardPosts] = @UserMessageBoardPosts, [UserSettingsUserGUID] = @UserSettingsUserGUID, [UserSettingsUserID] = @UserSettingsUserID, [WindowsLiveID] = @WindowsLiveID, [UserBlogPosts] = @UserBlogPosts, [UserWaitingForApproval] = @UserWaitingForApproval, [UserDialogsConfiguration] = @UserDialogsConfiguration, [UserDescription] = @UserDescription, [UserUsedWebParts] = @UserUsedWebParts, [UserUsedWidgets] = @UserUsedWidgets, [UserFacebookID] = @UserFacebookID, [UserAuthenticationGUID] = @UserAuthenticationGUID, [UserSkype] = @UserSkype, [UserIM] = @UserIM, [UserPhone] = @UserPhone, [UserPosition] = @UserPosition, [UserBounces] = @UserBounces, [UserLinkedInID] = @UserLinkedInID, [UserLogActivities] = @UserLogActivities, [UserPasswordRequestHash] = @UserPasswordRequestHash, [UserWebPartToolbarEnabled] = @UserWebPartToolbarEnabled, [UserWebPartToolbarPosition] = @UserWebPartToolbarPosition, [UserInvalidLogOnAttempts] = @UserInvalidLogOnAttempts, [UserInvalidLogOnAttemptsHash] = @UserInvalidLogOnAttemptsHash, [UserAvatarType] = @UserAvatarType, [UserAccountLockReason] = @UserAccountLockReason, [UserPasswordLastChanged] = @UserPasswordLastChanged WHERE [UserSettingsID] = @UserSettingsID: caused exception: Conversion failed when converting date and/or time from character string.

I do of course understand the exception but instead of me trying to hack around the object does anyone know why this is happening?

Thank you

User avatar
Kentico Legend
Kentico Legend
Brenden Kehren - 6/28/2013 7:14:56 AM
   
RE:Problem calling userinfo.update()
This could be the problem but might not be as well. The first thing that sticks out is that you have a custom UserSetting field called SalesForceId. If you are attempting to update that you need to have the UserSettingsInfo object. OR set the value like so
userInfo.UserSettings.SetValue("salesforceid", salesforceid);
Secondly I believe the best practice is to use the <Object>InfoProvider.Set<Object>Info(object) method. Here is an example
UserSettingsInfo usi = UserSettingsInfoProvider.GetUserSettingsInfo(userID);
if (usi != null)
{
// clean up the fields
usi.SetValue("UserTempCardNumber", 0);
usi.SetValue("UserLast4SSN", "");
UserSettingsInfoProvider.SetUserSettingsInfo(usi);
}
Best of luck!

User avatar
Member
Member
robert-pulldigital - 6/28/2013 8:03:45 AM
   
RE:Problem calling userinfo.update()
using the SetValue as we have been does set the property on the object in code, it's the call to update that failed but I have made the changes anyway as suggested and get the same exception

It's an odd one it's clearly taking the user object and as the date is 06/28/2013 it's throwing the age old exception of UK vs US!

Is it the case the SQL Server must be in the same locale as the site or perhaps a user profile setting or something in the web.config, when registering a user it is literally an email and password, the created date etc are all populated on the user object already, call .update and it throws the exception.

As a quick test I created a brand new user and called update on it and the exception is thrown.

User avatar
Member
Member
robert-pulldigital - 6/28/2013 9:19:05 AM
   
RE:Problem calling userinfo.update()
I must set the PreferredCultureCode property on the UserInfo object and the call to .Update succeeds. Why isn't this already set on the object when I am using the provider to retrieve the user from the database in the first place ? :)