Goal is to copy a list of the most resent attributes from a related table back to the Related Feature Class.
The feature class is called SampleSites, the related table is for collecting water samples for the that site.
Inspection Table is related to the Sample Sites GolbalID field and stored in a field called "SampleSites_Rel" in the Inspection Table
The Expression I am using now only gets the first record of the "inspection" variable in the Filter, I have tried "Max" and was not successful, I have tried to Sort the Table and failed " I had a wrong number of arguments" trying to add the sort to the expression.
var vFeature_SampleSiteGlobalID = $feature.GlobalID;
var InspectionTable = FeatureSetByName($datastore, "SDEP.SDEADMIN.WaterSampleInspections");
var Inspection = Filter(InspectionTable, "SampleSites_Rel = @vFeature_SampleSiteGlobalID");
var sv = first(Inspection);
if (sv != null) {
return {
"result" : {
"attributes" : {
"SampleDate" : sv.SampleDate,
"Cl" : sv.Cl,
"pH" : sv.pH,
"NH3" :sv.NH3,
"Color" :sv.Color,
"Temperature" : sv.Temperature,
"HPC" : sv.HPC
}
}
};
}
Any help would be much appreciated
Solved! Go to Solution.
You can use the OrderBy function to sort it and then get the first record of that ordered FeatureSet.
You can use the OrderBy function to sort it and then get the first record of that ordered FeatureSet.
Thank you that did the trick
added the variable to perform the Order
var InspectionOrderBy = OrderBy(Inspection, 'SampleDate DESC')
The Working code with the OderBy
var vFeature_SampleSiteGlobalID = $feature.GlobalID;
var InspectionTable = FeatureSetByName($datastore, "SDEP.SDEADMIN.WaterSampleInspections");
var Inspection = Filter(InspectionTable, "SampleSites_Rel = @vFeature_SampleSiteGlobalID");
var InspectionOrderBy = OrderBy(Inspection, 'SampleDate DESC')
var sv = first(InspectionOrderBy);
if (sv != null) {
return {
"result" : {
"attributes" : {
"SampleDate" : sv.SampleDate,
"Cl" : sv.Cl,
"pH" : sv.pH,
"NH3" :sv.NH3,
"Color" :sv.Color,
"Temperature" : sv.Temperature,
"HPC" : sv.HPC
}
}
};
}