Hi all,
With the new Calculated Expressions ability in field maps, I have some things that I have been wanting to try, so I've been getting into that today. However, I am no code-wizard, and don't really have the resources for help around me.
I think I'm pretty close with what I am wanting to do, but keep getting an error. I have a map that contains mostly point features that represent real world attributes, and we have time based inspections that we have to complete on thsese point features. The inspections are represented by related tables that are distinct to each of the point features. The point features also have a completion status field, that after the end-users submit a new inspection, needs to be changed to reflect the level of completion.
What I would like to do, is set up a calculated field in the completion status field, and have it look to the most recent inspection performed, and compare the date to a date window. I have posted my sample code below. The relationship is: GlobalID ("Odorizer" Feature) = ODGlobal ("Odorizer Inspection" Table)
var global = $feature.GlobalID; //declare Global ID of current feature as a variable to reference for relationship
var tblreads = FeatureSetByName($map, "Odorizer Inspection"); //get all of the related features as a variable
var sql = "ODGlobal = '" + global + "'"; // set up a query string
var relRead = Filter(tblreads,sql); // filter list of related records by Global-Guid Relationship. This gets only related records pertaining to feature in question.
var cnt = Count(relRead); // counts number of related records related to particular feature
var begWindow = date(03,01,2022); //sets the beginning of the completion window
var endWindow = date(03,31,2022); //sets the end of the completion window
var LastDate = ""; // empty variable to be used to pull last reading date from most recent related record
Console(cnt);
var recentMostRead = Top(OrderBy(relRead, 'ObjectID'),1); //creates a new variable to capture the most recent related record by ObjectID
LastDate += recentMostRead.CurrentReadDate; //dump the reading date field from the last related record into the LastDate variable created earlier.
if(begWindow < LastDate < endWindow) { //compare the date from the recent most related record to the completion windows called out above.
return "Completed, Not Approved";//If the record date is between the comparison dates, this should be the value in the field.
}
else {
return "Not Completed";//If the record date is NOT between the comparison dates, this should be the value in the field.
}Any help is appreciated! This will be applied to all of the rest of my point features in the map, so it will have a substantial impact I think.