Select to view content in your preferred language

Populate an attribute using Forms in AGOL map viewer

745
13
04-25-2024 01:40 PM
Labels (1)
SamanthaAPCC
Emerging Contributor

I'm hoping I'm close!  I was trying to do a similar thing using an Arcade Expression for symbology but I can't select the most recent feature.  So instead I'm writing the data to a new Field using Forms.

I have two datasets, a point dataset of sampling locations, and a corresponding pond polygon layer.  

The pond polygon layer will be public facing, and the symbology will reflect data gathered in the survey that populates the point feature class.  I have created a new, blank field in the pond polygon feature class that I'm hoping I can populate given a few criteria from the point layer.  Below is my arcade expression that I'm using in 'Forms' to calculate that blank field.  I need the pond to correspond to the correct points (hence the buffer in case they are slightly outside of the polygon), and I need the dates of the samples to be within 30 days.  As an option, if Intersect with a Buffer won't work, I do have an ID field that is identical between the point layer and the polygon layer.

 

 

// Define a Featureset (status) from the layer "Cyanobacteria_Public View" in the $map 
// that contains the attribute ['cyano_risk_tier']

var status = FeatureSetByName($map, "Cyanobacteria_Public View", ['cyano_risk_tier', 'fluorometry_date', 'final_review'])

// Define a variable (risk) to store the value we want
// Get the value by Intersecting the pond polygon location 
// with the FeatureSet "Cyano Ponds Public View", or status

var risk = Top(OrderBy(Intersects(status, Buffer($feature, 30, "meters")), 'fluorometry_date DESC'), 1);

var edit_datetime = Date(status['fluorometry date']);
var now_datetime = Now();
var days_dif = DateDiff(now_datetime, edit_datetime, "days");

// If the current location intersects the pond, 
// return the value in the field ['cyano_status']. 
// Otherwise, return a null value for areas where there is no intersecting polygon

var result = "No updated information";
if (!IsEmpty(risk) && (days_dif <30)) {
    return risk['cyano_risk_tier']
} else {
    return result
}

 

As a next step, if this works to populate the field in the pond polygon layer, I would also like to add on to this expression to allow for the following situations.  Occasionally, there are two sample sites for the same pond in the same day.  One sample site may have a lower 'cyano risk tier' than the other site.  I would like to default the 'cyano_status' to the higher of the 2 risk tiers.  So for example, if one sample site the risk is 'Acceptable', and at the second sample site the risk is 'Potential for Concern' (and these sites were sampled in the same day), I would need the overall risk for the pond to be 'Potential for Concern.'  In total there are 3 risks in the tier.

 

0 Kudos
13 Replies
KenBuja
MVP Esteemed Contributor

In Line 10 of your first post and line 20 in your second post, you're using Top to get the first record, but Top returns a FeatureSet, not a Feature. You have to use First instead to use that feature in the next line.

Try this (with a couple of other minor modifications)

// Define a Featureset (status) from the layer "Cyanobacteria_Public View" in the $map 
// that contains the attribute ['cyano_risk_tier']

var status = FeatureSetByName($map, "Cyanobacteria_Public View");

// Define a variable (risk) to store the value we want
// Get the value by Intersecting the pond polygon location 
// with the FeatureSet "Cyano Ponds Public View", or status
// var risk = Top(OrderBy(Intersects(status, Buffer($feature, 30, "meters")), 'fluorometry_date DESC'), 1);
// Not sure if this works
// Instead, try to match by CCC GIS ID

var CCC_GIS_ID = $feature.CCC_GIS_ID;
//var IDS = "CCC_GIS_ID = '" + CCC_GIS_ID + "'";
var RelatedReads = Filter(status, "CCC_GIS_ID = @ccc_GIS_ID");
//var numrelreads = count(RelatedReads);
if (Count(RelatedReads) == 0) return "No updated Information";

var LastSampleDate = First(OrderBy(RelatedReads, "fluorometry_date DESC"));
var edit_datetime = Date(LastSampleDate);
var now_datetime = Now();
var days_dif = DateDiff(now_datetime, edit_datetime, "days");
if (days_dif <= 30) return status['cyano_risk_tier'];
return "No updated Information";

 

0 Kudos
SamanthaAPCC
Emerging Contributor

Thanks for your help!  These updates make sense and I tested this new expression.  However, the field in my attribute table still isn't being populated.  This is my first time using Forms so I'm not sure if I'm missing another step in my set-up.  This expression is associated with the Field that I want populated, but not sure if there is another reason this isn't working.

0 Kudos
KenBuja
MVP Esteemed Contributor

Have you used @JosephRhodes2's suggestion to use console messages to check your variables at various steps?

0 Kudos
SamanthaAPCC
Emerging Contributor

Yes I've just been using it, I will get results I want, such as the CCC_GIS_ID, and I even made numrelreads active again and saw the count of 0 for the ID (which is fine, there are only 4 IDs at the moment that have a match between the 2 layers), but the text of 'No updated Information' won't write to the layer.  When I run the expression I also see the result of 'No updated Information' but again, the field in the layer remains empty in my map.

0 Kudos