Select to view content in your preferred language

planarize tool fails when return {"errorMessage"...} present in attribute rule

261
6
Jump to solution
a week ago
JohnHansen
Occasional Contributor

Hello again, 

I have created a single immediate attribute rule (triggered on Insert or Update) that does some validation of field values, and if everything is cool, updates a couple of additional fields. If the rule encounters bad values (in this case, Nulls), it should return with an errorMessage and not allow the operation to complete. The rule is working fine with every tool I have thrown at it so far, except for Planarize (with the rule disabled, Planarize does it's magic with no problem).

Just having a return {"errorMessage"...} statement present in the rule - even when it would not be accessed - causes the Planarize tool to just sit there:

hasNull = False

if (hasNull) {
return {"errorMessage":"NULL vals not allowed in CBT Fields"}
}

 

Planarize will work when the errorMessage is commented out:

hasNull = False

if (hasNull) {
return //{"errorMessage":"NULL vals not allowed in CBT Fields"}//
}

 

Any thoughts?

 

Thanks,

 

-John

0 Kudos
2 Solutions

Accepted Solutions
Jake_S
by Esri Contributor
Esri Contributor

@JohnHansen 

I modified your expression to use the Address Management Solution data and set this to a calculation rule (this most likely should be converted to a constraint or validation rule).

var hasNull = False
var parVal = $feature.fullname
if (IsEmpty(parVal)) { hasNull = True }
var alphaVal = $feature.stroute
if (IsEmpty(alphaVal)) { hasNull = True }
var subVal = $feature.strtetype
if (IsEmpty(subVal)) { hasNull = True }
var plssVal = $feature.ctyroute
if (IsEmpty(plssVal)) { hasNull = True }
var maplVal = $feature.onewaydir
if (IsEmpty(maplVal)) { hasNull = True }
var cntyVal = $feature.roadlevel
if (IsEmpty(cntyVal)) { hasNull = True }
if (hasNull) {
    return {"errorMessage":"NULL vals not allowed in CBT Fields"}
}

 
Using some ADMS sample data I inserted two lines. One who's end vertices intersects a line and one that overlaps. I preconfigured the field values so that the insert would have values.

Jake_S_2-1756132513091.png

 

When running the planarize tool against these features I get the same result. I went to the ArcGIS Pro Diagnostic Monitor and ran the planarize tool again to see what the logs showed. It shows that the rule is firing and logging the error.

Jake_S_3-1756132811220.png

If we can apply the rule below check what fields are empty to cause the rule to trigger the error message. The output is a concatenated list of all empty fields

var fullname_field = $feature.fullname
var stroute_field = $feature.stroute
var strtetype_field = $feature.strtetype
var ctyroute_field = $feature.ctyroute
var onewaydir_field = $feature.onewaydir
var roadlevel_field = $feature.roadlevel

var errorMessage
var nullFields = []

if (IsEmpty(fullname_field)) {
     Push(nullFields, "Full Name")
}
if (IsEmpty(stroute_field)) {
     Push(nullFields, "Street Route")
}
if (IsEmpty(strtetype_field)) {
     Push(nullFields, "Street Type")
}
if (IsEmpty(ctyroute_field)) {
     Push(nullFields, "City Route")
}
if (IsEmpty(onewaydir_field)) {
     Push(nullFields, "One Way Direction")
}
if (IsEmpty(roadlevel_field)) {
     Push(nullFields, "Road Level")
}
if (Count(nullFields) != 0) {
          errorMessage = "The following fields cannot be null: " + Concatenate(nullFields, ", ");
          return {"errorMessage": errorMessage}
}
return true

Looking at the logs it shows that there is an attempted insert with empty fields.

Jake_S_5-1756133196819.png


This validates why you are not seeing your first rule (var returnErrorMsg = True) triggering on insert and why the planarize tool does not complete. There is an underlying insert within the planarize tools code that inserts an empty row into the data source, that on this insert your code runs against empty values, returns an error without you seeing because that insert is not processed by the UI and thus the planarize would fail.

This tells us that with the Planarize tool there is an empty insert and then an update.

So with your current rule, one I copied with my field values, this may be expected behavior that the planarize tool 'fails'. But you can contact technical support to verify. 


 

View solution in original post

JohnHansen
Occasional Contributor

Based on @Jake_S's great investigate work, which shows that Planarize creates an empty insert and then updates the values based on the pre-planarize values, I needed to rewrite my rule so that it does not return with an errorMessage when it encounters null values. Once I did that, the Planarize tool works with the rule with no issues.

For those interested in how I did the rewrite, I still grab the field values, putting them into variables. I then check if any of those values are null, and if so, update the _variable_ value to, in this case, 'n':

var parVal = $feature.PAR
if (IsEmpty(parVal)) { parVal = 'n' }
var alphaVal = $feature.ALPHA
if (IsEmpty(alphaVal)) { alphaVal = 'n' }
var subVal = $feature.SUB
if (IsEmpty(subVal)) { subVal = 'n' }
var plssVal = $feature.PLSS
if (IsEmpty(plssVal)) { plssVal = 'n' }
var maplVal = $feature.MAPL
if (IsEmpty(maplVal)) { maplVal = 'n' }
var cntyVal = $feature.CNTY
if (IsEmpty(cntyVal)) { cntyVal = 'n' }

Later on in the rule, those _variable_ values get concatenated together and that combined value is used to update a separate field. I then drive symbology off of that field - when the value includes one or more 'n's, it is symbolized in red, alerting the user that there are null values that need to be fixed.

 

Thanks again, @Jake_S !

View solution in original post

0 Kudos
6 Replies
Jake_S
by Esri Contributor
Esri Contributor

@JohnHansen 

How is your rule checking values during insert? Are you requiring users to prefill values before inserting a new record? 

Do you get the same issue when you use the Split tool?

Reason I ask is the way ArcGIS Pro modifies data like this is there is an initial insert of a blank object in the database and then an update of attributes. So what users may perceive as only an update is actually and insert and update. It's just not seen. So if an attribute rule is not coded to handle this, such as checking inserts with prepopulated attributes, this may cause some unexpected behavior.

~Jake

0 Kudos
JohnHansen
Occasional Contributor

Thanks for the reply @Jake_S

I had already encountered the behavior you describe while testing/debugging, specifically with the Split tool. It appeared to me that sketching the line that is doing the splitting was being treated as an insert by my attribute rule, and because that sketch had null values for fields I was verifying, it was throwing an error. So I handled that in the rule code and everything was (is) working. 

Thus far, I have encountered this behavior only with the Planarize tool. As has happened for me in the past, immediately after I posted, I thought of a (hopefully) better way to test/confirm what is going on. I am in the process of slowly rebuilding the rule from scratch, adding in steps one at a time rather than working backwards by commenting things out. I am getting different results than what I was struggling with the last couple of days. If/when I pinpoint the issue, I will repost here.

0 Kudos
JohnHansen
Occasional Contributor

Taking a different approach, I have confirmed that there appears to be an issue when the Planarize tool encounters a return errorMessage in an attribute rule. I have also found that I may have a logic error that I can't figure out, which is at the end of this post. Any insights would be greatly appreciated.

Pro 3.5.2, immediate attribute rule, triggered on insert and update, both excluded and not excluded from application evaluation

One at a time, I have tested the following code blocks doing a Create, Copy, Reshape, Vert Move, Split, Intersect, and Planarize:

//returns message for create, and every tool except Planarize (planarize just doesn't complete)
var returnErrorMsg = True
if (returnErrorMsg) {
 return {"errorMessage":"Return with Error Message"}

//works with create and every tool including Planarize
var returnErrorMsg = False
if (returnErrorMsg) {
 return {"errorMessage":"Return with Error Message"}
}

//works with create and every tool including Planarize
var justReturn = True
if (justReturn) {
 return
}

Lastly, I am not seeing why this is not working for Planarize - it works with create and the other tools. None of the fields being accessed have Null values.
var hasNull = False
var parVal = $feature.PAR
if (IsEmpty(parVal)) { hasNull = True }
var alphaVal = $feature.ALPHA
if (IsEmpty(alphaVal)) { hasNull = True }
var subVal = $feature.SUB
if (IsEmpty(subVal)) { hasNull = True }
var plssVal = $feature.PLSS
if (IsEmpty(plssVal)) { hasNull = True }
var maplVal = $feature.MAPL
if (IsEmpty(maplVal)) { hasNull = True }
var cntyVal = $feature.CNTY
if (IsEmpty(cntyVal)) { hasNull = True }
if (hasNull) {
return {"errorMessage":"NULL vals not allowed in CBT Fields"}
}

 

Thanks for reading!

0 Kudos
Jake_S
by Esri Contributor
Esri Contributor

@JohnHansen 

I modified your expression to use the Address Management Solution data and set this to a calculation rule (this most likely should be converted to a constraint or validation rule).

var hasNull = False
var parVal = $feature.fullname
if (IsEmpty(parVal)) { hasNull = True }
var alphaVal = $feature.stroute
if (IsEmpty(alphaVal)) { hasNull = True }
var subVal = $feature.strtetype
if (IsEmpty(subVal)) { hasNull = True }
var plssVal = $feature.ctyroute
if (IsEmpty(plssVal)) { hasNull = True }
var maplVal = $feature.onewaydir
if (IsEmpty(maplVal)) { hasNull = True }
var cntyVal = $feature.roadlevel
if (IsEmpty(cntyVal)) { hasNull = True }
if (hasNull) {
    return {"errorMessage":"NULL vals not allowed in CBT Fields"}
}

 
Using some ADMS sample data I inserted two lines. One who's end vertices intersects a line and one that overlaps. I preconfigured the field values so that the insert would have values.

Jake_S_2-1756132513091.png

 

When running the planarize tool against these features I get the same result. I went to the ArcGIS Pro Diagnostic Monitor and ran the planarize tool again to see what the logs showed. It shows that the rule is firing and logging the error.

Jake_S_3-1756132811220.png

If we can apply the rule below check what fields are empty to cause the rule to trigger the error message. The output is a concatenated list of all empty fields

var fullname_field = $feature.fullname
var stroute_field = $feature.stroute
var strtetype_field = $feature.strtetype
var ctyroute_field = $feature.ctyroute
var onewaydir_field = $feature.onewaydir
var roadlevel_field = $feature.roadlevel

var errorMessage
var nullFields = []

if (IsEmpty(fullname_field)) {
     Push(nullFields, "Full Name")
}
if (IsEmpty(stroute_field)) {
     Push(nullFields, "Street Route")
}
if (IsEmpty(strtetype_field)) {
     Push(nullFields, "Street Type")
}
if (IsEmpty(ctyroute_field)) {
     Push(nullFields, "City Route")
}
if (IsEmpty(onewaydir_field)) {
     Push(nullFields, "One Way Direction")
}
if (IsEmpty(roadlevel_field)) {
     Push(nullFields, "Road Level")
}
if (Count(nullFields) != 0) {
          errorMessage = "The following fields cannot be null: " + Concatenate(nullFields, ", ");
          return {"errorMessage": errorMessage}
}
return true

Looking at the logs it shows that there is an attempted insert with empty fields.

Jake_S_5-1756133196819.png


This validates why you are not seeing your first rule (var returnErrorMsg = True) triggering on insert and why the planarize tool does not complete. There is an underlying insert within the planarize tools code that inserts an empty row into the data source, that on this insert your code runs against empty values, returns an error without you seeing because that insert is not processed by the UI and thus the planarize would fail.

This tells us that with the Planarize tool there is an empty insert and then an update.

So with your current rule, one I copied with my field values, this may be expected behavior that the planarize tool 'fails'. But you can contact technical support to verify. 


 

JohnHansen
Occasional Contributor

Wow - thanks so much for the time you put into this @Jake_S. It will take me some time to digest (and, unfortunately, to even get back to it for a couple of days). 

I am puzzling over your suggestion to convert to a constraint or validation rule, although I trust that you may be right. In the best practices post(s), I've seen many references to creating a single rule that does many things, instead of individual single-task rules. Perhaps I misunderstood, or don't yet understand the benefits/limitations of taking either approach. There is always so much to learn...

 

Thanks again - you rock!  

0 Kudos
JohnHansen
Occasional Contributor

Based on @Jake_S's great investigate work, which shows that Planarize creates an empty insert and then updates the values based on the pre-planarize values, I needed to rewrite my rule so that it does not return with an errorMessage when it encounters null values. Once I did that, the Planarize tool works with the rule with no issues.

For those interested in how I did the rewrite, I still grab the field values, putting them into variables. I then check if any of those values are null, and if so, update the _variable_ value to, in this case, 'n':

var parVal = $feature.PAR
if (IsEmpty(parVal)) { parVal = 'n' }
var alphaVal = $feature.ALPHA
if (IsEmpty(alphaVal)) { alphaVal = 'n' }
var subVal = $feature.SUB
if (IsEmpty(subVal)) { subVal = 'n' }
var plssVal = $feature.PLSS
if (IsEmpty(plssVal)) { plssVal = 'n' }
var maplVal = $feature.MAPL
if (IsEmpty(maplVal)) { maplVal = 'n' }
var cntyVal = $feature.CNTY
if (IsEmpty(cntyVal)) { cntyVal = 'n' }

Later on in the rule, those _variable_ values get concatenated together and that combined value is used to update a separate field. I then drive symbology off of that field - when the value includes one or more 'n's, it is symbolized in red, alerting the user that there are null values that need to be fixed.

 

Thanks again, @Jake_S !

0 Kudos