I came upon a weird issue yesterday. In one of our projects, we registered an Enterprise feature service to AGOL, and we use an Arcade field calculation to populate an "Inspector" attribute using GetUser($layer).username. As noted in previous threads, the .fullname property does not work offline, but the .username property does work offline.
However...we have found the following combination creates an unexpected result:
- If using GetUser($layer).username with a registered Enterprise feature service in AGOL
- ...with an offline map
- ...and in Airplane Mode (or cellular turned off)
- ...returns the Portal user name of the user who registered the Enterprise service to AGOL, instead of the currently logged-in AGOL user
Everything works fine if there is any sort of connectivity. In other words, works fine with an offline map as long as you have a pulse on your cellular. Also works fine with hosted layers, of course.
I did find a workaround:
- Create a new, empty hosted layer in AGOL
- Enable sync, add to the Field Map, turn off editing for the layer in Field Maps
- In Field Maps config, direct the getuser() function toward this AGOL hosted layer rather than the current registered Enterprise layer. ex:
var user = GetUser(FeatureSetByName($map,"Layer_Name"), true)
var username = user.username
Then everything works fine, just need to add a "fake" hosted layer into the map to force Field Maps to do the right thing.
Surely this is a bug? Returning the login info of the app seems like a pretty basic function, not sure why it's tied to the data layer and not the app itself. Am I missing something? Is there a more elegant way to do this that doesn't involve adding a fake layer?