Select to view content in your preferred language

Arcade: Get the previously entered values and fill field in table

771
0
10-17-2023 03:03 PM
Labels (3)
KristinVernon1
Occasional Contributor

I'm trying to write an arcade expression whereby when the current value is entered, the previous value entered (it would mostly be the day before).

EDIT: This table will be updated through field maps by field inspectors so they don't have a table view, they have a form view. Also, the numbers would be very long and varying, for example: 531660000 is a past value. This expression is being written as an attribute rule in the expression builder.

So the data table is set up like below:

KristinVernon1_0-1697579792473.png

Whereby gallons is calculated by Current Gallons - Previous Gallons.

Previous Gallons is supposed to be the amount off gallons from the day before. So instead of having the user try to remember the number (most of the time it would be a long number) I would like for this to be automatically entered. I started to write the below arcade expression, I want to get the last date's current gallons and enter into the current row's previous gallons.

// get related records
var fs = FeatureSetByName($datastore, "Operations.DBO.DailyInspection");

// sort the related records and get top 1
var ord = Top(OrderBy(fs, 'Date DESC'), 2);
var cg = $feature.CurrentGals;

// get the latest and previous features
var result = NULL;
if (Count(fs)==2) {
var cnt = 0;
for (var f in fs) {
cnt += 1;
if (cnt == 1) {
var f_latest = f;
} else if (cnt == 2) {
var f_prev = f;
}
}
// determine total gallons today and calculate increment
//var cases_latest = f_latest.NewCasesToday;
//var cases_prev = f_prev.NewCasesToday;
//result = f_latest - f_prev;
//return result;

var sql = " Date = @f_prev ";
var query = Filter(fs, sql);
var result = query.CurrentGals;
}

// return the result
return result;

 

I am stuck here could use a nudge in the right direction.

I'm getting the feeling that this isn't something that can be done with the lack of feedback I've been getting?

0 Kudos
0 Replies