Cant get modelbuilder to add Attribute Rules to a layer

1717
8
09-14-2021 04:06 PM
by Anonymous User
Not applicable

Hi there,
I am having an issue in ModelBuilder in ArcGIS Pro.

The issue:
In order to add Attribute Rules to a layer, it must first have a Global Id (the Add Global Ids tool will add the global ID in the attribute table). The layer must also have a field in which to apply the Attribute Rule to. Thus, you will see in my modelbuilder that I have first a field added to a layer (Add Field). I then have a global ID added to that layer (Add Global IDs). I then add an attribute rule to that layer. The Add Field and Add Global ID outputs are both set as parameters to the Attribute Rule. Despite this, the model keeps throwing me an error that reads something like "the layer must have a global ID." You will see that the Attribute Rule tool and its output are greyed out.

Here is a simplified section of my greater model that i'm having difficulty with:

Capture.PNG

So, it seems like the model is not recognizing that the layer has the global ID added to it within the process before the attribute rule is added. Adding attribute rules to the layer works if the Add Global IDs tool is run before running the model - but this negates the entire purpose of the model.

The Global ID cannot be added outside of the model, it must happen within the model for the purpose of my intended usage for this project.

Does anyone know how I can force the model to recognize that the global ID is applied within the model? Thank you in advance, I have much appreciation for anyone who can help me.

8 Replies
DanPatterson
MVP Esteemed Contributor

did you try adding the global id first, then add the other field

Add Global IDs (Data Management)—ArcGIS Pro | Documentation


... sort of retired...
0 Kudos
by Anonymous User
Not applicable

It works if I add the Global ID first outside of the model, then run the model. But unfortunately that doesn't really work for the purpose of this application. Thank you regardless.

0 Kudos
MichaelVolz
Esteemed Contributor

Can you break out the model into multiple models so that the first model would add the global id all within that model and the output of that model would be the input to the next model?

I would even suggest exporting the models out to python scripts and work with multiple python scripts in series.

0 Kudos
by Anonymous User
Not applicable

That's what I've been thinking that I'll have to do, that I'll have to have two models, one that adds the global ID and one that runs all the other processes. So, perhaps  this is a bug? Is there a more official place I can post this question to that can get the attention of someone at ESRI?

0 Kudos
DanPatterson
MVP Esteemed Contributor

You have to contact Tech Support


... sort of retired...
curtvprice
MVP Esteemed Contributor

I agree with Dan that the tool's validation should handle this in model builder, I think this is a bug (unless there is some limitation I don't know about), so please do contact tech support so they log a NIM to get this fixed.

When I run into this problem, I have been successful with this workaround: run the tool in arcpy inside a Calculate Value tool (using a Python arcpy call). This bypasses the ModelBuilder validation, causing the validation to happen later at runtime when the Calculate Value tool is run.  I realize this requires you know some python, but just a little bit. Make sure the output of the Add Field tool is connected to the Calculate Value tool as a precondition to make sure the field gets added first.

Expression:

arcpy.AddGlobalIDs_management(r"%Layer%")

Data Type:

Feature Layer

Just a note, your model variable name "new field that the attribute value will be applied to" is not accurate (the result of Add Field is a table or attribute table with the new field added).  A better label for this variable would be  something like: "layer with field added".

0 Kudos
by Anonymous User
Not applicable

Thank you very much for your helpful reply. Yes, I was thinking that perhaps a work-around would be running the model as a script. However...I have no idea where to even begin with that process. I will try to figure out how to run my actual model through arcpy instead. Do I first need to export the model as a python script, and import that code in arcpy? If this is not what you mean in your explanation, can you ELI5 about the calculate value tool and adding the script to it? Do you mean Calculate Field when you say Calculate Value?

 

Can I show you my actual model that I am trying to make work? Maybe that will help.

0 Kudos
curtvprice
MVP Esteemed Contributor

No, I did not suggest exporting the model, what I am suggesting is to use the Calculate Value (not Calculate Field) tool, which allows you to calculate expressions in Python. These expressions can include python code to run tools from arcpy, I gave you the parameters to use with the tool to do this. The idea is instead of running Add Global IDs in a tool like you have it, run the tool with a Python expression inside a Calculate Value tool to you can avoid the validation that is holding things up for you.  You can use preconditions to make sure the table is ready to go before you run the Calculate Value, and use its output as a precondition to your Add Attribute Rules runs to make sure your Calculate Value runs first.

Check out the help on Calculate Value, maybe that will help you understand what I am suggesting.

0 Kudos