API Questions on Kentico API.
Version 5.x > API > Update custom field in UserSettings table via API View modes: 
User avatar
Guest
rakeshtgupta - 8/4/2011 6:26:49 PM
   
Update custom field in UserSettings table via API
We have a custom field in User settings table, How can we Update custom field via API.
I tried this
UserSettingsInfo usi = UserSettingsInfoProvider.GetUserSettingsInfo(usersettingsid);
usi.SetStringValue(columnName, Value);
UserSettingsInfoProvider.SetUserSettingsInfo(usi);
But was not successful.

Any other procedure to do this?

Thank you,

User avatar
Kentico Developer
Kentico Developer
kentico_ivanat - 8/5/2011 1:27:25 AM
   
RE:Update custom field in UserSettings table via API
Hi,

Alternative way is using userInfo object, i.e. user.UserSettings.SetValue(columnName, value), but I tested your code and the record was updated correctly.


UserSettingsInfo usi = UserSettingsInfoProvider.GetUserSettingsInfo(1);
usi.SetStringValue("color", "blue");
UserSettingsInfoProvider.SetUserSettingsInfo(usi);


The row in the CMS_UserSettings table was updated correctly, for administrator user in default installation.

What exactly was not working in your case?

Thank you for information.

Best regards,
Ivana Tomanickova

User avatar
Guest
rakeshtgupta - 8/5/2011 11:09:53 AM
   
RE:Update custom field in UserSettings table via API
Hello Ivana,

Thanks for the reply.

Row in the CMS_UserSettings table was not Updating.
When I tried to debug the code.
After setting the value using usi.SetStringValue("color", "blue");
added a get statement usi.GetStringValue("color"); which is returning NULL.

Thanks and Regards,

Rakesh

User avatar
Kentico Developer
Kentico Developer
kentico_ivanat - 8/8/2011 1:59:00 AM
   
RE:Update custom field in UserSettings table via API
Hi,

the only way I could reproduce the issue, i.e. get null value as you described was in case the column "color1" was not created in the Site Manager - Development - System table - cms.user or cms.usersettings. Could you please check if you are using correct code name for your custom field (Attribute name in the field tab)?

UserSettingsInfo usi = UserSettingsInfoProvider.GetUserSettingsInfo(1);
usi.SetStringValue("color1", "red");
string color = usi.GetStringValue("color1");
UserSettingsInfoProvider.SetUserSettingsInfo(usi);


Best regards,
Ivana Tomanickova


User avatar
Guest
Sasha - 5/28/2013 5:06:10 AM
   
RE:Update custom field in UserSettings table via API
Hi,
I had the same problem.
I resovle it in this way:

1. userInfo.UserSettings.SetValue("a", a);
2. userSettings.SetValue("a", a);

(1) update manager
(2) update database.

The only way it works for me.

User avatar
Guest
Sasha - 5/28/2013 5:30:43 AM
   
RE:Update custom field in UserSettings table via API
Hi again,

my work friend find some nice solution to this problem:

userInfo.UserSettings.SetValue("a", a);

UserSettingsInfoProvider.SetUserSettingsInfo(userInfo.UserSettings);

It works fine.
Hope it will work for you