2

This is for Acumatica ERP 2021 R2:

I need to get the Default Warehouse Site for the current user. This is shown as part of the UserPreferences DAC, and the field name is DefaultSite

User Profile

Getting the UserPreferences seems easy enough:

            var curUsr = base.Base.Accessinfo.UserID;
            var usrPrefs = UserPreferences.PK.Find(graph, curUsr);

The problem is that the DefaultSite does not exist in the UserReferences DAC!

It exists in the SQL database table:

SQL SS

How do I get the DefaultSite field? It is NOT available to me in the DAC. I need it to retrieve the INSite record it references.

Here is a screenshot of my VStudio showing available fields, you can see that DefaultSite is missing.

VS Screenshot

MarkJoel60
  • 537
  • 2
  • 6
  • 24

1 Answers1

3

The DefaultSiteID is defined in the UserPreferenceExt DAC cache extension, so you just simply need to get the extension and use it like below:

var curUsr = base.Base.Accessinfo.UserID;
var usrPrefs = UserPreferences.PK.Find(graph, curUsr);

var usrPrefsExt = usrPrefs.GetExtension<UserPreferenceExt>();
var siteID = usrPrefsExt?.DefaultSite;
Samvel Petrosov
  • 7,580
  • 2
  • 22
  • 46
  • I should have thought to check that. Usually the extensions I have seen have the usr prefix, so I never considered this could be an extension, for some reason. Thanks! – MarkJoel60 Sep 13 '22 at 12:40
  • 1
    @MarkJoel60 I agree, this is actually a little strange that they have that field in that extension. – Samvel Petrosov Sep 13 '22 at 14:23