Select to view content in your preferred language

Field Map Auto-Populate Fails in the App and Can't Submit

248
5
11-22-2024 11:27 AM
ChristineAlevizos
Emerging Contributor

Hi All, 

Thank you for your support with this. 

 

I have several fields in a data layer that I have programmed to auto-populate with a value. For example, the name of an overlapping polygon. The function runs fine in the web designer and usually runs fine in the app.

Sometimes in the Field Map app- the value fails to populate. If this happens the field technician is unable to submit the point/ form. The field is not required so it should be able to submit without the data there. 

Does anyone have an explanation for why the auto-population would fail and a workaround to still be able to submit the form if the programming does fail? 

 

This is some example script that I am using: 

// Create a feature set using the 'POPREF' layer in the map
var regions = FeatureSetByName($map, 'POPREF', ['POPREF'])


// Intersect the current location with the regions and
// get the first region
var region = First(Intersects($feature, regions))


// If the current location does intersect a feature,
// return the name of the region. Otherwise, return null
if (!IsEmpty(region)) {
    return region['POPREF']
} else {
    return null
}

 

Thank you for your support!

0 Kudos
5 Replies
DougBrowning
MVP Esteemed Contributor

My guess is your intersect is getting nothing so when you try to use First it fails.  I would break that out and test the is empty on the result of the intersect before trying to use First.  Happened to me.

0 Kudos
ChristineAlevizos
Emerging Contributor

Hi Doug, 

 

Thank you very much for your support with this. 

 

Do you have any idea why I wouldn't be able to submit the form? I don't have it as a required field. I would be fine with the field being empty or null as long as the point can be submitted. 

Thank you again!

DougBrowning
MVP Esteemed Contributor

That is why I think its a script error and that is what is stopping it.  My guess is it goes into an error state and stops it from doing anything including submitting.

0 Kudos
ChristineAlevizos
Emerging Contributor

I understand!

Do you recommend I use something other than "First"?

Thanks!

0 Kudos
DougBrowning
MVP Esteemed Contributor

As I posted above you just need to check for empty before calling first.  Something like this.  In theory regions could be empty too so may have to check for that as well.

// Create a feature set using the 'POPREF' layer in the map
var regions = FeatureSetByName($map'POPREF', ['POPREF'])
 
// Intersect the current location with the regions and
// get the first region
var region = Intersects($featureregions)

 

// If the current location does intersect a feature,
// return the name of the region. Otherwise, return null
if (!IsEmpty(region)) {
    return First(region)['POPREF']
else {
    return null
}
0 Kudos