Tracking number of edits to features

2202
12
Jump to solution
06-09-2020 11:09 AM
MichailaMusman
New Contributor III

I have a question about tracking edits to hosted feature layers in AGOL.  I have points in the field that are being edited by our crew, and the last user to edit the points is being tracked.  I'm wondering if anyone has figured out how to track how many times a point is edited, through an arcade script or adding a new field to track this.

0 Kudos
12 Replies
XanderBakker
Esri Esteemed Contributor

Hi Michaila Musman ,

I am not sure what you mean exactly when you say "assign each new date field a variable and repeat the If else format". Can you explain what your schema looks like at this moment (especially what date fields you have up to now)? 

I hope you are not going to create a new field to store another date and maintain the history of each visit date. I assume you need to have information on the last date the tree was watered and comparing that with the current date will provide information on how long ago the tree was watered. However, a tree that was watered 5 days ago might not be in good conditions if the times before it wasn't watered in a long time. Are you sure you don't need that history?

0 Kudos
MichailaMusman
New Contributor III

Hi Xander Bakker‌,

Currently we have a field "Last_Water" which represents the most recent date a tree was watered.  We currently have five empty date fields for field staff to enter subsequent water dates. We also have a condition field "Mntc_Condn" that evaluates if a tree is dead, in which case it is excluded from the watering efforts. The last part of the above phrase, "plt_year", communicates which trees are prioritized for watering based on what year they were planted.

The workflow we had come up with was to update "Last_Water" and a second date field according to how many times a tree has been visited.  So if the tree has been watered once, it will have the same date entered in "Last_Water" and "Water_1."  Upon the second time a tree is watered, the field staff will update "Last_Water" to the current date, and update the field "Water_2" with the current date as well, leaving Water_1 unchanged with the first water date. In this way we have Last_Water communicating the most recent water with fields Water_1, Water_2, ...Water_n tracking the watering history.  We are over halfway through our watering season, so updating the feature layer to work with a related table isn't really worth our time at this point in the season.

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi Michaila Musman , 

From what I understand, you don't need to access the Water_# fields to get the last date and you don't need them to determine the water status that you are after. So the expression that you already had should solve the problem. Below a slightly changed version:

// check if dead
if (DomainName($feature,"Mntc_Condn") == "Dead") {
    return "Dead";
}

// check is you have a last date
var last_water = $feature["Last_Water"];
if (IsEmpty(last_water)) {
    return "N/A";
}

var result = "";
var days = DateDiff(Now(), last_water, "days");

if (days <= 14) {
    result = "Watered";
} else if (days > 14) {
    result = "Needs Water (" + $feature["plt_year"] + ")";
} 

return result;

If you want to do some statistics over the water_# fields you can use the expression below to play around:

function GetStats(arr, stat) {
    // Get stats and ignore Null values in array
    var result = Null;
    if (Upper(stat) == "MIN") {
        // calculate min
        for (var i in arr) {
            if (!IsEmpty(arr[i])) {
                if (IsEmpty(result)) {
                    result = arr[i];
                } else {
                    if (arr[i] < result) {
                        result = arr[i];
                    }
                }
            }
        }
    } else if (Upper(stat) == "MAX") {
        // calculate max
        for (var i in arr) {
            if (!IsEmpty(arr[i])) {
                if (IsEmpty(result)) {
                    result = arr[i];
                } else {
                    if (arr[i] > result) {
                        result = arr[i];
                    }
                }
            }
        }
    } else if (Upper(stat) == "COUNT") {
        // count elements that are not null
        for (var i in arr) {
            if (!IsEmpty(arr[i])) {
                if (IsEmpty(result)) {
                    result = 1;
                } else {
                    result += 1;
                }
            }
        }
        
    } else {
        Console("Invalid statistic...");
    }
    return result;
}

// Define some dates (you would read those from the Water_# fields directly)
var date1 = Date(2020, 7, 1);
var date2 = Date(2020, 1, 2);
var date3 = Date(2020, 2, 3);
var date4 = Null;
var date5 = Date(2020, 4, 5);

// create an array with the dates
var dates = [date1, date2, date3, date4, date5];

// calculate some statistics and print to the console
Console(GetStats(dates, "min"));
Console(GetStats(dates, "max"));
Console(GetStats(dates, "count"));

return "OK";
0 Kudos