Form Calculate GetUser() Offline

5879
39
04-21-2022 10:56 AM
CraigCheeseman
New Contributor III

Has anyone had success calculating the username when offline?  Documentation says I should be able to use the layer.  Works testing but does not work in app.

var u = getUser($layer);
var fullName = u.fullName;
return fullName;

39 Replies
kmsmikrud
Regular Contributor

Yes it works or its been working and biologists are collecting data in Alaska working on skiffs/remotely...... Full name would not work because when offline you only have access to the Field Maps username as they are signed in. I think I tried fullName and that did work only online. That is my understanding/experience.

 

0 Kudos
BrantCarman
Occasional Contributor

Oh super interesting!  I just tested dow here in WA and GetUser() does indeed work with username when disconnected!  Thanks @kmsmikrud for pointing this out 😄

Still, First and Last name do appear to be stored locally in the app (under profile, next to username), and ESRI has this logged as a bug that is under consideration currently: BUG-000155887 

Using username is a potential workaround for some of what I'm trying to do, but not ideal.  Would be great if others in this forum could escalate with ESRI so the bug gets enough traction for possible fix in the next Field Maps release.  To escalate I think you need to open a case and have ESRI support attach the case to the bug, and then you have the option to escalate further in My Esri.

kmsmikrud
Regular Contributor

I'm glad that 'username' works for you. Thanks also for sharing about First and Last name being stored in the app. The way we have our usernames is basically the first "." last, so that is why I had the split of the username and then proper function.

I also added a table basically as a lookup table to the web map and then query the table for username to get the initials to add into our sample number field. This has worked offline, except in order for the lookup table calculation to query we are needing to download the offline map from the device created offline area. The AGOL web map settings generated offline map for whatever reason fails on this calculation offline. I did submit a tech support case and a bug was logged, but good info to have in hand if a calculation is failing try another method for generating offline maps - it may just work? On the backend how the offline maps are generated between the device generated and web map settings is somehow a little different.

Maybe this is another potential work around with a lookup table ? So many bugs to keep track of.

NevilleWilson_Everick
New Contributor III

This is a really annoying bug.

Why is there never a full and complete fix to a problem.

0 Kudos
willbruce_KarukTribeDNR
Occasional Contributor

Wow thank you! Not sure exactly why this works, but this is great. Just finished coding up some forms that pull a bunch of default values from an initial 'settings' FeatureSet filtered by username, and found that GetUser() by itself did not work in Field Maps. Your solution works for me, online and offline.

0 Kudos
cbp-geus
Occasional Contributor II

Are there any updates on this issue? We need to be able to log the full name of our geologists and not just their username when they are collecting data in the field in Greenland. The following code works fine when online, but not when taking the device offline:

 

GetUser(FeatureSetByName($map, 'Locality')).fullname

 

Screenshot_20240304_082157_Field Maps.jpg
When looking at the offline data in ArcGIS Field Maps, the username is stored in the geodatabase and offline feature dataset, but the full name of the user are available in the ArcGIS Field Maps user credentials for the user that are logged in. Why can't we get the information from that instead?
 
Christian Brogaard Pedersen
willbruce_KarukTribeDNR
Occasional Contributor

Christian, it's a bit annoying, but as a workaround, I store some default data (including full names) in a separate layer, use the username to filter that table down to a single record, and then pull the values into the form.

var context = $editcontext.edittype
var settings = FeatureSetByName($map, 'layer', ['*'], false)
var currentuser = GetUser(settings).username
var filtered_settings = Filter(settings, 'AGOL_User = @currentuser')

if (context == 'INSERT' && Count(filtered_settings) > 0){
  return First(filtered_settings).FieldName
}else {
  return $feature.FieldName
}
0 Kudos
cbp-geus
Occasional Contributor II

I had considered the same thing, but it seems just so complicated for such a single record 😅

Instead, we decided make a join with a table that contains all the full names when we extract the fielddata from the Field Maps. It's a shame that we have to bother with it, but we can't risk locking the field app when we're in the field.

Christian Brogaard Pedersen
0 Kudos
BrantCarman
Occasional Contributor

I tried using a table for this. Works in online map, but fails in offline map, even when not fully disconnected... Does Field Maps not support hosted tables in offline maps? I tried using a point feature layer as well, but any features that fall outside of offline area aren't downloaded. Maybe this would work if I added records to the table without geometry?

Curious how you made this work 😅

0 Kudos
BrantCarman
Occasional Contributor

Okay, I've confirmed that the offline area doesn't appear to download my hosted table, and this is why the calculation fails. I tried using a point FS with records added to attribute table and no actual point geometry (appended my table to the host point feature layer). This also doesn't work; I believe the offline map is not downloading the records needed for filter() function.

The only way I can see that this seems to work is if I have a feature within the download area that gets downloaded and can be used as lookup record.

So my workaroud will be to try and create a polyline or polygon FL that contains a bunch identical features which span across the state of Washington and will be captured by any one of the offline areas our surveyors might use. Feature attributes will contain my lookup data. This is insanely messy...

If anybody has a better solution, I'd love to hear it. or if @JeffShaner and team can help with this bug (ENH-000157471), I think a lot of people could benefit.

Thanks!

0 Kudos