Skip to main content
Answer

How to reference the field 'UserPreferences.DefaultSite' in a customization

  • July 17, 2025
  • 4 replies
  • 57 views

lauraj46
Captain II
Forum|alt.badge.img+8

Acumatica customization gurus, is it possible to reference the UserPreferences.DefaultSite field in an event?  Code snippet is below, but I’m receiving the error ‘UserPreferences’ does not include a definition for ‘DefaultSite’.   The field does exist in the SQL table in my local test environment.  Thanks in advance!

 

            var line = e.Row;
            var currentUserID = PXAccess.GetUserID();


            UserPreferences prefs = PXSelect<UserPreferences,
                Where<UserPreferences.userID, Equal<Required<UserPreferences.userID>>>>
                .Select(Base, currentUserID);

            if (prefs?.DefaultSite != null)
            {
                line.SiteID = prefs.DefaultSite;
            }

 

 

Best answer by MichaelShirk

Hey ​@lauraj46 the DefaultSite field is actually defined in a DAC extension, not in the base, UserPreferences DAC. 

See this example where I needed to default a field value to the current user’s default site. 
The DefaultSite field is defined in UserPreferenceExt. 

 

            [PXDefault(typeof(SelectFrom<INSite>
.LeftJoin<UserPreferences>
.On<UserPreferenceExt.defaultSite.IsEqual<INSite.siteID>>
.Where<UserPreferences.userID.IsEqual<AccessInfo.userID.FromCurrent>>),
PersistingCheck = PXPersistingCheck.Nothing)]

 

This should work for you (using Fluent BQL). 

 


var line = e.Row;
var currentUserID = PXAccess.GetUserID();

var userPref = SelectFrom<UserPreferences>
.Where<UserPreferences.userID.IsEqual<@P.AsGuid>>
.View.ReadOnly.Select(Base, currentUserID)
?.GetExtension<UserPreferenceExt>();

if (userPref?.DefaultSite != null)
{
line.SiteID = userPref.DefaultSite;
}

 

 

4 replies

MichaelShirk
Captain II
Forum|alt.badge.img+5
  • Captain II
  • Answer
  • July 17, 2025

Hey ​@lauraj46 the DefaultSite field is actually defined in a DAC extension, not in the base, UserPreferences DAC. 

See this example where I needed to default a field value to the current user’s default site. 
The DefaultSite field is defined in UserPreferenceExt. 

 

            [PXDefault(typeof(SelectFrom<INSite>
.LeftJoin<UserPreferences>
.On<UserPreferenceExt.defaultSite.IsEqual<INSite.siteID>>
.Where<UserPreferences.userID.IsEqual<AccessInfo.userID.FromCurrent>>),
PersistingCheck = PXPersistingCheck.Nothing)]

 

This should work for you (using Fluent BQL). 

 


var line = e.Row;
var currentUserID = PXAccess.GetUserID();

var userPref = SelectFrom<UserPreferences>
.Where<UserPreferences.userID.IsEqual<@P.AsGuid>>
.View.ReadOnly.Select(Base, currentUserID)
?.GetExtension<UserPreferenceExt>();

if (userPref?.DefaultSite != null)
{
line.SiteID = userPref.DefaultSite;
}

 

 


darylbowman
Captain II
Forum|alt.badge.img+15

...the DefaultSite field is actually defined in a DAC extension...

 

The DAC Schema Browser actually indicates this with [Customized]:

Futhermore, if you click on the [Customized] box, it will open a dialog with information about the customization.


DipakNilkanth
Pro III
Forum|alt.badge.img+13

Hi ​@lauraj46,

DefaultSiteID is declared under UserPreferenceExt (PX.Objects.dll) ,not in UserPreference DAC.

You can use below code snippet to achieve the same.

var line = e.Row;
var currentUserID = PXAccess.GetUserID();

// Get the UserPreferences record
UserPreferences prefs = PXSelect<UserPreferences,
Where<UserPreferences.userID, Equal<Required<UserPreferences.userID>>>>
.Select(Base, currentUserID);

if (prefs != null)
{
// Access the extension
var ext = PXCache<UserPreferences>.GetExtension<UserPreferenceExt>(prefs);

if (ext?.DefaultSite != null)
{
line.SiteID = ext.DefaultSite;
}
}

Hope, it helps!


lauraj46
Captain II
Forum|alt.badge.img+8
  • Author
  • Captain II
  • July 18, 2025

Thank you ​@MichaelShirk , ​@darylbowman and ​@Nilkanth Dipak for the help!  This all makes sense and worked perfectly.  This community is the best.

Laura