Select to view content in your preferred language

Modelbuilder: Why is <u"> being added to my calculation values?

170
7
Wednesday
Labels (1)
RandyMcGregor_BMcD
Frequent Contributor

I have a simple calculation in a Calculate Field tool in modelbuilder. %Field Name% is a variable that references an actual field that is in the attribute table.

RandyMcGregor_BMcD_0-1767194030601.png

This is what the results look like:

RandyMcGregor_BMcD_1-1767194135032.png

I have been using inline variable substitution regularly and have never seen anything like this. If I double-click the field from the drop-down, instead of using '!%Field Name%!', it works as desired.

Does anyone know what is going on here and how to correct it? 

Thank you,

Randy McGregor

 

0 Kudos
7 Replies
CodyPatterson
MVP Regular Contributor

Hey @RandyMcGregor_BMcD 

Would it be possible to test the function without the exclamation points? I remember having an issue where the exclamation points were causing an issue, but I'm unfortunately no longer able to test and can only give suggestions!

Cody

RandyMcGregor_BMcD
Frequent Contributor

That populated the field with the name of the field. I tried Arcade and had the same effect. I have no memory of ever having to clarify that I want the contents of the field, rather than it's name to populate reccords. I'm either having an end-of-year brain freeze, or something strange is going on. 'ParishXed3' is the name of the field.

RandyMcGregor_BMcD_0-1767208394461.png

RandyMcGregor_BMcD_1-1767208458066.png

If I select the field from the drop-down, it works fine:

RandyMcGregor_BMcD_2-1767208618670.png

RandyMcGregor_BMcD_3-1767208671628.png

 

 

 

 

0 Kudos
RandyMcGregor_BMcD
Frequent Contributor

Thanks for the suggestion. I'll give it a try.

0 Kudos
RandyMcGregor_BMcD
Frequent Contributor

Oookay, so I went back to python and put the "!" marks outside of the quote marks and that works.  There's some trick to getting arcade to recognize that you are asking for the value within the field, rather than the field's name, but I don't know what it is.

RandyMcGregor_BMcD_4-1767209401722.png

 

0 Kudos
VenkataKondepati
Regular Contributor

This is a ModelBuilder evaluation-order issue, not user error.

Inline substitution (%Field Name%) is resolved before Calculate Field runs, but the expression itself is parsed later. The result is that the substituted value is treated as literal text, not a field reference — which is why you see the field name written into the row.

Don’t use inline substitution inside Calculate Field expressions. Always use the actual field token (!FieldName!) or resolve the expression first (e.g., with Calculate Value) and pass it in.

The %variables% and Calculate Field don’t play nicely together due to timing — explicit field tokens are the safe path.

Regards,
Venkat
RandyMcGregor_BMcD
Frequent Contributor

Thank you very much for that explanation. Very interesting.

 

0 Kudos
RandyMcGregor_BMcD
Frequent Contributor

I did have luck with !'%field name variable%'! though. Keeping the explamation marks outside the quote marks worked. I think your advice will help with Arcade expressions. I'll give it a try.