Showing results for 
Search instead for 
Do you mean 

A little code snippet to help you with user options....

by on ‎06-10-2010 06:15 AM

There will come a time when you might want to store some setting for the current user and then retrieve them when they log in later. A great place to do this is within the user options section of SLX. This way you don't have to great another table in the database for this data, plus using the code below it is super easy to do!


The code below shows you two different methods. One called "GetSearchItems" and another called "cmdUpdate_Click1". When "GetSearchItems" is called it will first create a IUserOptionsService object based off the logged in user. This alone is cool because you don't have to worry about setting it up for the logged in user, it's all in context for you. Next you simply call the "GetCommonOption" method and pass in two params. The first one is the group/category the item you are looking for is in. The second one is the actual name of the item within that group/category.


Now the second method will update a user option. You first create the IUserOptionsService as before but this time you call the "SetCommonOption" method. This method takes an extra param and that is the value of the item you are storing. You still pass the group/category and the items name params.

protected string GetSearchItems() { IUserOptionsService userOption = Sage.Platform.Application.ApplicationContext.Current.Services.Get<IUserOptionsService>(); return userOption.GetCommonOption("Group", "Item"); } protected void cmdUpdate_Click1(object sender, EventArgs e) { IUserOptionsService userOption = Sage.Platform.Application.ApplicationContext.Current.Services.Get<IUserOptionsService>(); userOption.SetCommonOption("Group", "Item","Value",true); }



I've used this code many times and it is a great way to store simple settings for the logged in user. I really hope you get some mileage out of it as well!

by Employee
on ‎09-08-2010 07:51 AM


Good stuff.


Do you have any examples of adding a new tab to the Options area so users have a place to set custom options?

on ‎05-03-2012 02:47 PM

Thanks for the clue.


I'm using a .net extension through the LAN Client and this the was the clue I needed.


Although the implementation and classes used are a bit different


_slxApplication is the ISLXApplication instance required in .net extensions that is passed in from the LAN Client when the .net cl;ent initializes


Using a Try Catch in case the CustomUserOption I am attempting to read does not exist at all.


Options.Add add the default entry into the useroptionsdef table with the default value.




				HideDeleted = _slxApplication.UserOptions.GetAsBoolean (SHOW_HIDE_DELETED_USEROPTION, USER_OPTION_CATEGORY);
			catch (Exception)
				HideDeleted = false;

Later in the code, I am setting the individual user option using 


_slxApplication.UserOptions.SetAsBoolean (SHOW_HIDE_DELETED_USEROPTION, USER_OPTION_CATEGORY, _hideDeleted, false);

It's pretty straight forward oce you know it's there. 

Register Read Guidelines Request Partner or Employee Access

What's New in 8.1