Geoprocessing Service Input Never Changes

2792
4
Jump to solution
07-01-2016 01:39 PM
LeviRoberts
Occasional Contributor

Hello all,

I have a simple geoprocessing service (for now) that I want to look at a feature class on my SDE, look at a specific row, count all the NULL values, then email me that number. I have it working like a champ in ArcMap and I even have the email working great when it's a service. The issue I'm running into is when I change the number of values that are NULL, the geoprocessing service seems to be looking at a copy of what was there when I first published it. So if I had 20 values that were NULL when I published it then went back and tweaked the data to be 10 values, when I run the service it will still email me that 20 are NULL values.

I can't figure out if I'm referencing the data wrong in my geoprocessing script, or if there is something else I'm missing.

# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------------
# hyperlinkPopulate.py
# Created on: 2016-07-01 08:54:14.00000
#   (generated by ArcGIS/ModelBuilder)
# Description: 
# ---------------------------------------------------------------------------


# Import arcpy module
import arcpy
import smtplib


# Local variables:
CROOKADMIN2_DBO_cornersTest = "Database Connections\\CROOKADMIN2.sde\\CROOKADMIN2.DBO.grids\\CROOKADMIN2.DBO.cornersTest"
DBO_cornersTest_Layer = "DBO.cornersTest_Layer"


# Process: Make Feature Layer
arcpy.MakeFeatureLayer_management(CROOKADMIN2_DBO_cornersTest, DBO_cornersTest_Layer, "hyperlink IS NULL", "", "OBJECTID OBJECTID VISIBLE NONE;alpha alpha VISIBLE NONE;hyperlink hyperlink VISIBLE NONE;GlobalID GlobalID VISIBLE NONE;township township VISIBLE NONE;range range VISIBLE NONE;numeric numeric VISIBLE NONE;lastedited_who lastedited_who VISIBLE NONE;lastedited_date lastedited_date VISIBLE NONE;Shape Shape VISIBLE NONE")


rows = arcpy.SearchCursor(DBO_cornersTest_Layer, fields="hyperlink")


numCorners = 0


# Iterate through the rows in the cursor and count the number of new records
for row in rows:
  numCorners = numCorners + 1
  #emailList.append(row.getValue("EMAIL"))


#A bit more stuff that doesn't matter

There's more that has to do with the emailing but doesn't matter.

0 Kudos
1 Solution

Accepted Solutions
LeviRoberts
Occasional Contributor

Turns out all I needed to do was include the Clear Workspace Cache tool at the beginning of my script. Now runs like a champ.

# Import arcpy module
import arcpy
import smtplib


# Local variables:
CROOKADMIN2_DBO_cornersTest = "Database Connections\\CROOKADMIN2.sde\\CROOKADMIN2.DBO.grids\\CROOKADMIN2.DBO.cornersTest"
DBO_cornersTest_Layer = "DBO.cornersTest_Layer"


# Process: Clear Workspace Cache
arcpy.ClearWorkspaceCache_management("")


# Process: Make Feature Layer
arcpy.MakeFeatureLayer_management(CROOKADMIN2_DBO_cornersTest, DBO_cornersTest_Layer, "hyperlink IS NULL", "", "OBJECTID OBJECTID VISIBLE NONE;alpha alpha VISIBLE NONE;hyperlink hyperlink VISIBLE NONE;GlobalID GlobalID VISIBLE NONE;township township VISIBLE NONE;range range VISIBLE NONE;numeric numeric VISIBLE NONE;lastedited_who lastedited_who VISIBLE NONE;lastedited_date lastedited_date VISIBLE NONE;Shape Shape VISIBLE NONE")


rows = arcpy.SearchCursor(DBO_cornersTest_Layer, fields="hyperlink")


numCorners = 0


# Iterate through the rows in the cursor and count the number of new records
for row in rows:
  numCorners = numCorners + 1

# Process: Calculate Field
arcpy.CalculateField_management(DBO_cornersTest_Layer, "hyperlink", "'ftp://Surveys:*@share.co.crook.or.us/Monuments/*@share.co.crook.or.us/Monuments/' + !township! + !range! + !alpha! + '-' + !numeric! + '.pdf'", "PYTHON_9.3", "")


View solution in original post

4 Replies
LeviRoberts
Occasional Contributor

Here is what it looks like once published on server.

# Esri start of added imports
import sys, os, arcpy
# Esri end of added imports


# Esri start of added variables
g_ESRI_variable_1 = os.path.join(arcpy.env.packageWorkspace,u'CROOKADMIN2.sde\\CROOKADMIN2.DBO.grids\\CROOKADMIN2.DBO.cornersTest')
g_ESRI_variable_2 = u'DBO.cornersTest_Layer'
g_ESRI_variable_3 = u'hyperlink IS NULL'
g_ESRI_variable_4 = u'OBJECTID OBJECTID VISIBLE NONE;alpha alpha VISIBLE NONE;hyperlink hyperlink VISIBLE NONE;GlobalID GlobalID VISIBLE NONE;township township VISIBLE NONE;range range VISIBLE NONE;numeric numeric VISIBLE NONE;lastedited_who lastedited_who VISIBLE NONE;lastedited_date lastedited_date VISIBLE NONE;Shape Shape VISIBLE NONE'
# Esri end of added variables


# -*- #################
# ---------------------------------------------------------------------------
# hyperlinkPopulate.py
# Created on: 2016-07-01 08:54:14.00000
#  (generated by ArcGIS/ModelBuilder)
# Description:
# ---------------------------------------------------------------------------


# Import arcpy module
import arcpy
import smtplib


# Local variables:
CROOKADMIN2_DBO_cornersTest = g_ESRI_variable_1
DBO_cornersTest_Layer = g_ESRI_variable_2


# Process: Make Feature Layer
arcpy.MakeFeatureLayer_management(CROOKADMIN2_DBO_cornersTest, DBO_cornersTest_Layer, g_ESRI_variable_3, "", g_ESRI_variable_4)


rows = arcpy.SearchCursor(DBO_cornersTest_Layer, fields="hyperlink")


numCorners = 0


# Iterate through the rows in the cursor and count the number of new records
for row in rows:
  numCorners = numCorners + 1
MAIL"))
0 Kudos
ModyBuchbinder
Esri Regular Contributor

When you publish it copies the connection file to local directory.

Is your connection windows or rdbms authentication? - the user that runs the service is different from your map.

Is the layer you try to access versioned?

0 Kudos
LeviRoberts
Occasional Contributor

Hi Mody,

The layer is versioned.

The connection is rdbms and the user in the in the connection files seems to match (unless I'm looking in the wrong spot).

Someone pointed me towards this thread Clear Workspace Cache in Python​, but not entirely clear on what he did.

Thanks for the help on this.

0 Kudos
LeviRoberts
Occasional Contributor

Turns out all I needed to do was include the Clear Workspace Cache tool at the beginning of my script. Now runs like a champ.

# Import arcpy module
import arcpy
import smtplib


# Local variables:
CROOKADMIN2_DBO_cornersTest = "Database Connections\\CROOKADMIN2.sde\\CROOKADMIN2.DBO.grids\\CROOKADMIN2.DBO.cornersTest"
DBO_cornersTest_Layer = "DBO.cornersTest_Layer"


# Process: Clear Workspace Cache
arcpy.ClearWorkspaceCache_management("")


# Process: Make Feature Layer
arcpy.MakeFeatureLayer_management(CROOKADMIN2_DBO_cornersTest, DBO_cornersTest_Layer, "hyperlink IS NULL", "", "OBJECTID OBJECTID VISIBLE NONE;alpha alpha VISIBLE NONE;hyperlink hyperlink VISIBLE NONE;GlobalID GlobalID VISIBLE NONE;township township VISIBLE NONE;range range VISIBLE NONE;numeric numeric VISIBLE NONE;lastedited_who lastedited_who VISIBLE NONE;lastedited_date lastedited_date VISIBLE NONE;Shape Shape VISIBLE NONE")


rows = arcpy.SearchCursor(DBO_cornersTest_Layer, fields="hyperlink")


numCorners = 0


# Iterate through the rows in the cursor and count the number of new records
for row in rows:
  numCorners = numCorners + 1

# Process: Calculate Field
arcpy.CalculateField_management(DBO_cornersTest_Layer, "hyperlink", "'ftp://Surveys:*@share.co.crook.or.us/Monuments/*@share.co.crook.or.us/Monuments/' + !township! + !range! + !alpha! + '-' + !numeric! + '.pdf'", "PYTHON_9.3", "")