Trying to create a fairly simple attribute rule on a line feature that will take various values from a table and divide them by another field containing the calculated length of the segment in miles and then return the result to the appropriate fields. This is set to trigger on insert and update
// Retrieve values and handle nulls
var lengthMiles = $feature.LengthMiles;
var totalCrashes = DefaultValue($feature.TotalCrashes, 0);
var fatalCrashes = DefaultValue($feature.FatalCrashes, 0);
var injuryCrashes = DefaultValue($feature.InjuryCrashes, 0);
var propertyCrashes = DefaultValue($feature.PropertyCrashes, 0);
var pedestrianGenerator = DefaultValue($feature.PedestrianGenerator, 0);
// Initialize the result dictionary
var result = {
'CrashesPerMile': 0,
'FatalCrashes_PerMile': 0,
'InjuryCrashes_PerMile': 0,
'PropertyCrashes_PerMile': 0,
'PedGen_PerMile': 0
};
// Calculate per mile values if lengthMiles is greater than 0
if (lengthMiles > 0) {
result['CrashesPerMile'] = totalCrashes / lengthMiles;
result['FatalCrashes_PerMile'] = fatalCrashes / lengthMiles;
result['InjuryCrashes_PerMile'] = injuryCrashes / lengthMiles;
result['PropertyCrashes_PerMile'] = propertyCrashes / lengthMiles;
result['PedGen_PerMile'] = pedestrianGenerator / lengthMiles;
}
// Return the result object
return result;
The check tells me that the rule is valid but when I go to create a new line on the map, I get this error:
Triggering event: Insert,
Class name: PublicWorksInternal.DBO.TrafficCalmingProjects,
GlobalID: {345DBCDD-2B43-4EF1-9BF8-94F0A82ACFBA}]Undefined keyword is used in the dictionary return script. [CrashesPerMile]
Thanks for any help!
Solved! Go to Solution.
@BillMoody you'll need to use proper distortionary keywords to insert the values into the proper attributes. The documentation is here, Attribute rule dictionary keywords.
~Jake
@BillMoody you'll need to use proper distortionary keywords to insert the values into the proper attributes. The documentation is here, Attribute rule dictionary keywords.
~Jake
Most welcome!! @BillMoody