Select to view content in your preferred language

Auto-filling date-time start and end for a polyline in Field Maps

169
3
Jump to solution
3 weeks ago
EricaNova
Frequent Contributor

I have a layer set up in field maps called 'Nest searches'. Users collect a polyline showing where they searched for bird nests by streaming their location in the field. 

I want Field Maps to automatically calculate the date-time start for the polyline, and the date-time end.

Ideally, when the user clicks "collect", the current date-time will fill the field 'date_time_start'. When the user toggles 'yes' on the field 'track_complete', the current date-time will fill the field 'date_time_end'. 

This is happening properly within field maps on my iPhone, but as soon as I press submit, both those values are recalculated. 

Without collecting m-values for these lines, is there another way to force Field Maps NOT to recalculate upon submit? AI is not helping me out here, it's out of ideas.

Here's the two expressions I'm currently using that aren't working:

// Only set the start time if it hasn't been set already

if (IsEmpty($feature.Date_time_start)) {

    return Now();

} else {

    return $feature.Date_time_start;

}

 

// Only return the current time if "Track_complete" is 'yes'

if ($feature.Track_complete == "yes" && IsEmpty($feature.Date_time_end)) {

    return Now();

} else {

    return $feature.Date_time_end;

}

0 Kudos
1 Solution

Accepted Solutions
EricaNova
Frequent Contributor

Thanks Mitchell! A search of your suggestion to use originalFeature solved the issue - but, ironically, by not using originalFeature! Here's the original post: 

Field Maps Arcade Expression/Calculation - Only calculate for new features or when field is empty?

I'm now using these two expressions for my start and end time fields; and it's working as expected.

// Only set the start time if it hasn't been set already 
var starttime = IIf(IsEmpty($feature.Date_time_start), Now(), $feature.Date_time_start)
return starttime
// Only return the current time if "Track_complete" is "yes" 
var endtime = IIf(($feature.Track_complete == "yes" && IsEmpty($feature.Date_time_end)), Now(), $feature.Date_time_end)
return endtime

 

View solution in original post

3 Replies
MitchellGrafstein
Frequent Contributor

I believe you will have to evaluate $originalFeature for the IsEmpty function calls.  This will evaluate the feature prior to edits beginning.  You will also want to return $originalFeature.Date_time_start and $originalFeature.Date_time_end for the two expressions, as well.

EDIT - Having re-read your post, I might change my mind on this.  For how this is calculating on submit, unfortunately, I believe Field Maps continually recalculates whenever the form changes and I believe this includes upon submission.  Not sure if there is a way to capture "now" and hold it, but I believe it would be somewhat close to what you're doing (although I think originalFeature has to play in somewhere.)  My apologies that this post became a lot less helpful; I might test this - the idea of how long a form takes to be filled out comes to mind, so I might just check that.

Mitchell Grafstein, Horticultural Inspector 1, NYS Dept. of Agriculture and Markets
EricaNova
Frequent Contributor

Thanks Mitchell! A search of your suggestion to use originalFeature solved the issue - but, ironically, by not using originalFeature! Here's the original post: 

Field Maps Arcade Expression/Calculation - Only calculate for new features or when field is empty?

I'm now using these two expressions for my start and end time fields; and it's working as expected.

// Only set the start time if it hasn't been set already 
var starttime = IIf(IsEmpty($feature.Date_time_start), Now(), $feature.Date_time_start)
return starttime
// Only return the current time if "Track_complete" is "yes" 
var endtime = IIf(($feature.Track_complete == "yes" && IsEmpty($feature.Date_time_end)), Now(), $feature.Date_time_end)
return endtime

 

MitchellGrafstein
Frequent Contributor

You're welcome, Erica, and I was coming around to a similar conclusion about not using $originalFeature from some testing I did this morning.   Just got back around to checking the forums.  Glad you found a solution that worked, and appreciate that you posted it, as well.

Mitchell Grafstein, Horticultural Inspector 1, NYS Dept. of Agriculture and Markets