GetUser() When Offline and Disconnected

1574
3
03-07-2023 09:22 AM
DanielMiranda2
Occasional Contributor

I have seen a few discussions about GetUser() not working when using Field Maps in a disconnected environment:

Form Calculate GetUser() Offline - Esri Community

Some discussion above was a bit muddled because not everyone was tested in a disconnected environment. Ultimately, no solution worked while offline.

Solved: Field Maps, Offline Map, Arcade Calculation Expres... - Esri Community

BUG-000155887: Arcade expressions fail to calculate when using offl.. (esri.com)

The two above links seem to suggest that this is in fact, a bug that may be addressed down the road.

Has anyone come up with a way to get the current user's information in Field Maps when offline? Or do we have to wait until a bug fix/enhancement is released? 

The only workaround I could think of was to use editor tracking fields, but these fields are not populated until after a data point is collected. So form calculations needing this information will not have it unless the user re-edits the newly added point. This is not a great solution.

When we use Field Maps, many users like to create IDs in their data that includes their initials. This should be easily automated.

 

3 Replies
DanielMiranda2
Occasional Contributor

I have done some more research into this and believe I have found a more viable solution.

What specifically does not work when offline is:

 GetUser($layer).fullName

 Using firstName or lastName also does not work. When I checked the Field Maps mobile app error log, the actual error for the Arcade expression is "field_not_found."

So clearly, a user's full name is not part of the dictionary returned by GetUser. So instead, I tried the following:

GetUser($layer).username

I figured, the editor tracking fields clearly have access to usernames, so maybe GetUser() does too. This DOES work while offline. When I say offline I mean my device is in airplane mode and I am using either an offline area created on the device, or an offline area created in Field Maps Designer. I tested both.

 

In my specific case, our organization uses first initial and last name as part of their usernames, so I can still get the information I want. I won't mark this as a solution though, as it is not quite as good as retrieving a full name. I also find it frustrating that this is not documented anywhere in the Field Maps references or the Arcade reference.

DougBrowning
MVP Esteemed Contributor

They said at Dev Summit that full name does not work yet since it is not part of the offline info and they are working to find a way to support it.

MitchellGrafstein
Occasional Contributor

I created a bit of a workaround for this if anyone is interested.  I would imagine this workaround is not practical or applicable for all use cases, but it is still something.  I literally have not tested this offline, but I see no reason why it would not work, since the table in question could be synced and available offline.  (I will test that in the coming weeks, but I figured the concept was worth sharing.)

For an unrelated task, I created a table with key (field) names, and lookup values to search for, then "value" field names, and values to return.  I initially put last_edited_user to try and populate this, but that only hits the form on submit (so it couldn't actively apply from the lookup table.) 

Instead, I used the GetUser($layer) [thanks for that formatting by the way], and searched on the table I added to the form.

MitchellGrafstein_0-1715014309805.png

var result = null // set the result variable to null so this expression will return null if the search field is empty/null

var key_name = 'key_name' // the field that contains the keys which are field names that will be used in the FeatureSet filter
var key_lookup = 'key_lookup' // the field that contains the lookup value from the form

var lookup_field = 'lookup_field' // the field that we will search on which contains field names as values
var lookup_value = 'lookup_value' // the field that contains the desired value

var lookup_fields_of_interest = [key_name,lookup_field,key_lookup,lookup_value] // the list of the fields of interest which are set above

var key_name_search = "last_edited_user" // the lookup value used to filter the FeatureSet --> key_name=@key_name_search
// in a sense, key_name_search is a nested key found in the key_name field
// key_name _search is also the field in the form we're interested in
var lookup_field_search = 'toughpad_user' // the value to look up in the lookup_field --> lookup_field=@lookup_field_search


var username=GetUser($layer).username // only used for searching on the logged-in username
// if(!(IsEmpty($feature[key_name_search]))){ // code to use if searching for a field in the form (which matches the key_name field in the table)
if(!(IsEmpty(username))){ // code to use if searching for the username of the logged-in user

var search_value = username // the field in the form/feature used for the lookup --> key_lookup=@search_value

var lku_fset = FeatureSetById($map, /* LKUs Table Feature Service - treatment lkus tbl */ "18f0b3902e4-layer-30",lookup_fields_of_interest,false)

    // had to explicitly name the field in the filter, using @Variable for the field name was not returning the proper values
    // tested if variable name matching the field name mattered, it did not, could not use @Variable for the field name in the filter
    // MG - 2024-04-23
    result = First(Filter(lku_fset, 'key_name=@key_name_search AND lookup_field=@lookup_field_search AND key_lookup=@search_value'))[lookup_value]

// }
}
return result 
Mitchell Grafstein, Horticultural Inspector 1, NYS Dept. of Agriculture and Markets