I am helping our city Fire Department to conduct fire hydrant inspections. One of the inspection steps is to take several readings (static pressure, residual pressure and pilot pressure) from the hydrant to determine flow gallons per minute (GMP). Typically, they would take these readings and have to put them into a third-party program that then does the calculations to in the background to get GPM.
I have an Arcade script that will allow the GPM to be determined in the field once the required numbers are input in the appropriate fields. I have run script in Pro with no problems. I wanted to add an attribute rule with a triggering event of 'Update' and 'Insert' so when they either go to an existing hydrant or add a new one and conduct a flow test the GPM will be calculated on the fly. It runs as expected on existing hydrants. However, when I try to add a new hydrant I am receiving an error. Any guidance would be greatly appreciated! Please see error message, script and set up of geoprocessing tool below.
ERROR MESSAGE:
ARCADE SCRIPT:
var P = $feature.pilotpress
var S = $feature.staticpress
var R = $feature.respress
var Q = 167.0625 * Sqrt(P);
var RF = Q * Pow(((S - 20) / (S - R)), 0.54);
return RF
GEOPROCESSING TOOL SETUP:
Solved! Go to Solution.
Hi Ari Lukas ,
The moment you submit the new feature, do you have values in the fields pilotpress, staticpress and respress? If not you will be performing the calculations with null values. It would be better to include a validation that checks if the values are null and avoids performing the calculation when not all values have been specified yet.
Can you try this expression?
// function to validate if any of the values have not been set yet
Function ContainsEmptyValue(arr) {
var validation = False;
for (var i in arr) {
if (IsEmpty(arr[i])) {
return True;
}
}
return validation;
}
// read values
var P = $feature.pilotpress;
var S = $feature.staticpress;
var R = $feature.respress;
// validate values
if (ContainsEmptyValue([P, S, R]) == False) {
// all value are available, calculate Q and RF
var Q = 167.0625 * Sqrt(P);
var RF = Q * Pow(((S - 20) / (S - R)), 0.54);
return RF;
} else {
// one or more values havve not been set, return null
return null;
}
Hi Ari Lukas ,
The moment you submit the new feature, do you have values in the fields pilotpress, staticpress and respress? If not you will be performing the calculations with null values. It would be better to include a validation that checks if the values are null and avoids performing the calculation when not all values have been specified yet.
Can you try this expression?
// function to validate if any of the values have not been set yet
Function ContainsEmptyValue(arr) {
var validation = False;
for (var i in arr) {
if (IsEmpty(arr[i])) {
return True;
}
}
return validation;
}
// read values
var P = $feature.pilotpress;
var S = $feature.staticpress;
var R = $feature.respress;
// validate values
if (ContainsEmptyValue([P, S, R]) == False) {
// all value are available, calculate Q and RF
var Q = 167.0625 * Sqrt(P);
var RF = Q * Pow(((S - 20) / (S - R)), 0.54);
return RF;
} else {
// one or more values havve not been set, return null
return null;
}
Hello Xander,
Thank you, that worked like a charm!!
Hi adlukas1 ,
I'm glad that it works. Can you mark the answer as the correct answer? Thanks!
Hi Xander,
Hoping that you can help me with an Insert triggering event that deletes records in a matching table. I have a feature class, GasFittings, for which we assign TagIds. Once a tag is assigned to a gas fitting, I would like to delete the matching tag from a master table of available tags. I did try to somewhat follow the example here: https://www.esri.com/arcgis-blog/products/arcgis-pro/data-management/advanced-gdb-attribute-rules-editing-external-features-with-attribute-rules/, but I was not able to achieve what I wanted. Here is what I have so far and I am just getting started with Attribute Rules. Ant help is greatly appreciated.
//The attribute rule is added to the TagID table on the Field "TagID", which executes a delete for records in Tag table with matching TagID in GasFit Layer
//Get Gas Fit layer
var gasfeature = $feature.AGLTAGID;
var relate = "$feature.name = '" + $feature.AGLTAGID + "'";
//Get TagID Table
var tagidtable = FeatureSetByName($datastore, "Tags");
var match = Filter(tagidtable, relate)
//if we couldn't find it exit (someone might've deleted it)
if (count(match) == 0) return $feature.name;
//get the feature row (we should only have one )
var matchingFeature = first(match)
return {
//we want to just return the value of field `name` no change require
"result": $feature.name,
//this keyword indicates an edit that need to happen, its an array since we can make many edits
"edit": [
{
//the other class we want to edit
"className" : "Tags",
//the type of edit, in this case we want to delete so we say `deletes`, its an array since we can make many deletes
"deletes" : [
{
//what feature we need to delete?
"name" : matchingFeature.name
}
]
}