> ## Documentation Index
> Fetch the complete documentation index at: https://docs.superoffice.com/llms.txt
> Use this file to discover all available pages before exploring further.

# SetPreference

> How to set preferences using SoPreference at the data layer

To find an overview of the available references, we may use methods such as `GetSections()` and `GetKeys()` exposed in the `SoPreference` class.

## Code

The following example shows how we can change the calendar start date (Sunday or Monday) for a given user.

```csharp theme={null}
using SuperOffice.Data;
using SuperOffice;
using(SoSession mySession = SoSession.Authenticate("sam", "sam"))
{
    SoPreference.SetPreference("Visual", "SundayFirstDay", true);
}
```

## Walk-through

Here we use the `SetPreference` method of the `SoPreference` class. The method provides four overloads depending on the input value, which could be either a string, int, DateTime, or bool value.

The first two parameters (preference section and the corresponding preference key) are always set and they are both of string types. Here, the last parameter is the new value used.

Once the code is executed the results can be seen through the application:

![Calendar -screenshot][img1]

The relevant section from the code that made the above change is:

```csharp theme={null}
SoPreference.SetPreference("Visual", "SundayFirstDay", true);
```

## GetSections

When setting preferences, we may need to know what sections are already found in the database. To get the available sections, we may call `GetSections()`. The method will return an array of all sections defined for the current associate from the cache if possible or from the database. However, it is possible to add your own preference sections to the application.

```csharp theme={null}
string[] test2 = SoPreference.GetSections();
```

## GetKeys

Once we have figured out which section to use, the next is to get the specific key, which relates to the part that we are planning to change. For this, we use the `GetKeys` method. The method gets all available keys within a section from the cache or the database.

```csharp theme={null}
string[] test = SoPreference.GetKeys("Visual");
```

Through the above code segment, we get the available keys, which are within the section called *Visual*.

See also: [intro to cache][1]

[1]: ../../../caching/index

[img1]: /media/loc/en/api/entities/start-week-sunday.png


## Related topics

- [Set Pref Value_ P O S T](/en/api/reference/restful/rest/preference/set-pref-value_-p-o-s-t.md)
- [Set Pref Value](/en/api/reference/restful/rest/preference/set-pref-value.md)
- [Set Pref Value At Level](/en/api/reference/restful/rest/preference/set-pref-value-at-level.md)
- [Set Pref Value At Level_ P O S T](/en/api/reference/restful/rest/preference/set-pref-value-at-level_-p-o-s-t.md)
- [NSPhoneListAgent](/en/automation/crmscript/reference/CRMScript.NetServer.NSPhoneListAgent.md)
- [Set Preferences](/en/api/reference/restful/agent/phonelist_agent/set-preferences.md)
- [SuperOffice.WebApi.Data.PhoneList SetPreferencesRequest](/en/api/reference/webapi/SuperOffice.WebApi.Data.PhoneList_SetPreferencesRequest.md)
