Select to view content in your preferred language

Publish simple tool with calculate

992
9
04-25-2017 12:45 AM
ModyBuchbinder
Esri Regular Contributor

Hello all

I have a one line python script that looks like this:

arcpy.CalculateField_management(r"DemandPoints1","from1",'"aaa"',"PYTHON_9.3")

from1 is a text field in DemandPoints1 and I would like to put the value aaa in it.

This script runs with no problem as tool (no parameters) in ArcMap but when I try to publish it as geoprocessing service I get:

24046: Tool <value> cannot use VB expressions for services
There are many examples of complex calculations but I would like to make it simple!!
Any ideas?

0 Kudos
9 Replies
DanPatterson_Retired
MVP Emeritus

exclamation marks for fields when using python ie !FieldName! could be the issue

http://desktop.arcgis.com/en/arcmap/latest/tools/data-management-toolbox/calculate-field-examples.ht...

0 Kudos
ModyBuchbinder
Esri Regular Contributor

I know that! I need to put a VALUE not a field value.

0 Kudos
by Anonymous User
Not applicable

Hi Mody,

Can you provide us more information like,

ArcGIS server installed on which OS?

Is there only issue with this GP process?

From first look like is related to selection on labeling.

0 Kudos
ModyBuchbinder
Esri Regular Contributor

I am using ArcGIS Server 10.3.1 on windows.

The tool is published and works. It just gives warning (level High) when I analyse before publishing.

Looks like a bug to me. 

0 Kudos
by Anonymous User
Not applicable

Ohh

Thanks for the information. 

0 Kudos
ModyBuchbinder
Esri Regular Contributor

Hi Dan

Thanks, as usual you are correct.

They only problem is that I do not have any VB expression in my python code.

That is why I think it is a bug.

0 Kudos
DanPatterson_Retired
MVP Emeritus

Which is why I pointed it out... it said to ignore it if you don't have a vb expression or to fix it if you do.  Confusing needless to say, but perhaps the simple example that you were testing is too simple and 'it' thinks it is vb.. perhaps try something more complicated (well not really) but is truly python...

"{}".format("aaa") which of course yields 'aaa'

RandyBurton
MVP Alum

After running the tool in ArcMap, if you go to Geoprocessing > Results and right-click on Calculate Field and select Copy As Python Snippet, it produces the following code:

# ArcMap 10.2.1 - Fails, doesn't like """"aaa""""
arcpy.CalculateField_management("DemandPoints1","from1",""""aaa"""","PYTHON_9.3","#")

# ArcMap 10.5 - Success
arcpy.CalculateField_management(in_table="DemandPoints1", field="from1", expression="'aaa'", expression_type="PYTHON_9.3", code_block="")‍‍‍

Here are other variations I have tried: 

arcpy.CalculateField_management("DemandPoints1","from1","{}".format("aaa"),"PYTHON_9.3","#") # fails

arcpy.CalculateField_management("DemandPoints1","from1","{}".format("'aaa'"),"PYTHON_9.3","#") # success

arcpy.CalculateField_management("DemandPoints1","from1",'aaa',"PYTHON_9.3","#") # fails

arcpy.CalculateField_management("DemandPoints1","from1","aaa","PYTHON_9.3","#") # fails

arcpy.CalculateField_management("DemandPoints1","from1","'aaa'","PYTHON_9.3","#") # success‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos