Using Inline Variable Substitution in Field Calculator in ArcGIS Pro

arcgis-promodelbuilder

I am putting together a model that will look at a field called "gridcode" that has values 1, 2, and 3. Depending on which value it has, it will calculate another field called Class_Name2. The values in Class_Name2 will depend on inline variable substitution because I want to use this for datasets that may have different values.

However, when I run the model it says the class value I typed in is not defined, even though I am defining them with a model parameter.

Here is my model, where Class 1, Class 2, Class 3, are set as strings and preconditions to the Field Calculator. These values will be typed in and substituted in the model when I run the tool in the second screenshot. The substitution is defined as %Class 1%, %Class 2%, and %Class 3%, respectfully.

My problem is the third screenshot. I am not sure what else I should add so the model clearly sees that it is text. I tried to add '"' + to either side of the %Class 1% but that did not help. Neither did str().

Any ideas on how to improve this model?

enter image description here

enter image description here

enter image description here

Best Answer

In the Calculate Field code block you need to enclose your substitution in double quotes so the return line should be

return "%Class 1%"

repeat for the others.