Select to view content in your preferred language

Need Help Modifying this code for my Attribute Rule

529
2
Jump to solution
04-14-2023 08:31 AM
BrianHumphries1
Emerging Contributor

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

0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor

You can use the OrderBy function to sort it and then get the first record of that ordered FeatureSet.

View solution in original post

2 Replies
KenBuja
MVP Esteemed Contributor

You can use the OrderBy function to sort it and then get the first record of that ordered FeatureSet.

BrianHumphries1
Emerging Contributor

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
      }
    }
  };
}

 

 

0 Kudos