Hi Hussein,
I'm on Pro 3.2.2 right now. I experience the problem in the Attribute Rules view, as that's the only place I know of to view or edit the rules. Is there some other view or menu in Pro where this can be accomplished?
I tried a simple rule like you suggested. With the simple rule, I can save, then add a comment, then save again as expected. No problem there. Unfortunately, complex rules are the ones that require the most debugging, tweaking, and resaving. I can't help but wonder at what point exactly does a rule go from "simple enough" to "too complex". Or maybe it's not a matter of complexity but just some specific aspect of the code?
Here's the expression for the more complex rule I'm working with. Aside from not being able to save expression changes after initially saving, the rule does perform exactly as I want...
// This rule works by by drawing a driveway line from the Road Centerline to the Site Address Point.
// The first vertex must touch a Road Centerline.
// The last vertex must touch a Site Address Point.
// Checks for an existing Address Point sitting on Road Centerline at the first vertex.
// If no Address Point is present, one will be created.
// Address Points, Site Address Points and Driveway lines have their own unique IDs: ADD-#, SID-#, and DRW-#
// This rule will pull the SID-#, the new DRW-#, and the ADD-# (whether existing or newly created)
// The rule will push the DRW-# and ADD-# values into the Site Address Point foreign key fields.
// The rule will bring the SID-# and ADD-# into the Driveway line foreign key fields.
// Define the Driveway Line fields
Expects($feature, 'DRWID')
var drw_idfield = 'DRWID';
var drw_sapkeyfield = 'SITEADDID'; //note: string must be hard coded in return statement, variable name won't work (unless I set up a dictionary first using the variable names, then call the dictionary in the return statement (?) like "adds" array
var drw_adpkeyfield = 'ADDPTKEY';
//Define the Site Address Point feature class name
var siteaddress_fc = 'SiteAddressPoint';
// Define the Site Addresses fields
var sap_idfield = 'SITEADDID';
var sap_adpkeyfield = 'ADDPTKEY';
var sap_drwkeyfield = 'ENTID';
//Define the Address Point feature class name
var addresspoint_fc = 'AddressPoint';
// Define the Address Point fields
var adp_idfield = 'ADDRESSPTI';
//Define the Road Centerline feature class name
var roads_fc = 'RoadCenterline';
// This function will Get a new id for the address point
function getAddressPointID() {
// Define the name of the database sequence and the format for the id
var myId = NextSequenceValue("AddressPointID");
return `ADD-${myId}`;
}
// Get the geometry and id (DRW-#) of the driveway line
var geom = Geometry($feature);
var myDrwID = $feature[drw_idfield];
// Get the vertices of the feature
var vertices = []
var firstPoint = null;
var lastPoint = null;
for (var part in geom.paths) {
var segment = geom.paths[part];
// Loop through the points in the segment
for (var i in segment) {
if (IsEmpty(firstPoint)) {
firstPoint = segment[i];
continue;
}
Push(vertices, segment[i]);
lastPoint = segment[i];
}
}
if (Count(vertices) < 1) return { "errorMessage" : "Line must have at least 2 vertices" }
// Find any intersecting roads with the first vertex
// If no roads intersect, return an error message, preventing the driveway and address point from being created
var intersectingRoads = Intersects(FeatureSetByName($datastore, roads_fc, ['*'], true), firstPoint);
if (Count(intersectingRoads) == 0) return { "errorMessage": "First vertex must intersect at least one Road Centerline" }
// Check for a Site Address Point intersecting with the last vertex
var intersectingSAP = Intersects(FeatureSetByName($datastore, siteaddress_fc, ['*'], true), lastPoint);
var mySAP = First(intersectingSAP);
var mysapGlobalID = "";
var mysapID = "";
if (mySAP == null){
return { "errorMessage": "End point of Entrance Connection line must intersect one Site Address Point. None found." };
} else if (Count(intersectingSAP) != 1) {
return { "errorMessage": "End point of Entrance Connection line must intersect one Site Address Point. More than one found." };
} else {
mysapGlobalID = mySAP.globalID;
mysapID = mySAP[sap_idfield];
}
// Check for an existing Address Point intersecting with the first vertex
// If none exists, create one.
// If one does exist, do not add a new one. Multiple driveways may originate at the same Address Point, even on opposite sides of the road. In such a case, the one Address Point is shared.
// More than one Address Point in the exact same spot is not expected.
var intersectingADP = Intersects(FeatureSetByName($datastore, addresspoint_fc, ['*'], true), firstPoint);
var adpCount = Count(intersectingADP);
var addressPointAdds = []
var addressptid = ""
if (adpCount == 0) {//There is no existing Address Point found
// Get an ID for the new Address Point
addressptid = getAddressPointID();
// And Construct a Point object
var myAdpPoint = Point({"x": firstPoint["x"], "y": firstPoint["y"], "spatialReference": Geometry($feature)["spatialReference"]})
Push(addressPointAdds, {
'attributes': Dictionary(
adp_idfield, addressptid
),
'geometry': myAdpPoint
})
} else if (adpCount > 1) {
return { "errorMessage": "More than one Address Point in the exact same spot is not expected"}
} else if (adpCount == 1) {
// Then get the ID of the existing Address Point
var myIntAdp = First(intersectingADP)
IIf(myIntAdp==null,null,addressptid = myIntAdp[adp_idfield])
}
return {
'result': {//put SID-# and ADD-# into this driveway line
'attributes': {
"SITEADDID": mysapID,
"ADDPTKEY": addressptid
}
},
'edit': [{//put ADD-# and DRW-# into the Site Address Point
'className': siteaddress_fc,
'updates': [{
'globalID': mysapGlobalID,
'attributes': {
'ADDPTKEY': addressptid,
'ENTID': myDrwID
}
}]
}, {//add new AddressPoint (if an existing one was not detected)
'className': addresspoint_fc,
'adds': addressPointAdds
}]
}
And for what it's worth, here are the rule options I'm using: just the "Insert" trigger and "Exclude from application evaluation"