<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic How to force python script (=geoprocessing service) to return results??? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/how-to-force-python-script-geoprocessing-service/m-p/275907#M21283</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi!&lt;/P&gt;&lt;P&gt;I need to make a little geoprocessing service based on python script... &lt;/P&gt;&lt;P&gt;Meaning of the service is easy: receive JSON, look if there are any features of one feature class in geodatabase and return the count of features...&lt;/P&gt;&lt;P&gt;General idea of script (as it looks like as a desktop script - thats why there are "AddMessage") is this:&lt;/P&gt;&lt;PRE class="python" name="code"&gt;import arcpy data="Database Connections\myDB.sde\MYDB.DATAOWNER.data" data_fl=arcpy.MakeFeatureLayer_management(data) json=arcpy.GetParameter(0) sr=arcpy.Describe(vo).spatialReference polygon=arcpy.AsShape(json,True) polygon.projectAs(sr) polygon_fl=arcpy.MakeFeatureLayer_management(polygon) arcpy.SelectLayerByLocation_management(data_fl,"INTERSECT",polygon) if arcpy.GetCount_management(data_fl).getOutput(0)!="0": &amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.arcpy.AddMessage("you have chosen "+arcpy.GetCount_management(data_fl).getOutput(0)+" features") else: &amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.arcpy.AddMessage("no chosen features")&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But - I know this is not way how to get some results from geoprocessing service (if i publish this script). &lt;STRONG&gt;How to force python script (=geoprocessing service) to return results???&lt;/STRONG&gt; It must be easy, I think this is kind of "newbie" question, Im still learning... &lt;SPAN aria-label="Blush" class="emoticon-inline emoticon_blush" style="height:16px;width:16px;"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for any help!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 16 Oct 2014 15:40:38 GMT</pubDate>
    <dc:creator>J_B__K_</dc:creator>
    <dc:date>2014-10-16T15:40:38Z</dc:date>
    <item>
      <title>How to force python script (=geoprocessing service) to return results???</title>
      <link>https://community.esri.com/t5/python-questions/how-to-force-python-script-geoprocessing-service/m-p/275907#M21283</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi!&lt;/P&gt;&lt;P&gt;I need to make a little geoprocessing service based on python script... &lt;/P&gt;&lt;P&gt;Meaning of the service is easy: receive JSON, look if there are any features of one feature class in geodatabase and return the count of features...&lt;/P&gt;&lt;P&gt;General idea of script (as it looks like as a desktop script - thats why there are "AddMessage") is this:&lt;/P&gt;&lt;PRE class="python" name="code"&gt;import arcpy data="Database Connections\myDB.sde\MYDB.DATAOWNER.data" data_fl=arcpy.MakeFeatureLayer_management(data) json=arcpy.GetParameter(0) sr=arcpy.Describe(vo).spatialReference polygon=arcpy.AsShape(json,True) polygon.projectAs(sr) polygon_fl=arcpy.MakeFeatureLayer_management(polygon) arcpy.SelectLayerByLocation_management(data_fl,"INTERSECT",polygon) if arcpy.GetCount_management(data_fl).getOutput(0)!="0": &amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.arcpy.AddMessage("you have chosen "+arcpy.GetCount_management(data_fl).getOutput(0)+" features") else: &amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.arcpy.AddMessage("no chosen features")&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But - I know this is not way how to get some results from geoprocessing service (if i publish this script). &lt;STRONG&gt;How to force python script (=geoprocessing service) to return results???&lt;/STRONG&gt; It must be easy, I think this is kind of "newbie" question, Im still learning... &lt;SPAN aria-label="Blush" class="emoticon-inline emoticon_blush" style="height:16px;width:16px;"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for any help!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Oct 2014 15:40:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-force-python-script-geoprocessing-service/m-p/275907#M21283</guid>
      <dc:creator>J_B__K_</dc:creator>
      <dc:date>2014-10-16T15:40:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to force python script (=geoprocessing service) to return results???</title>
      <link>https://community.esri.com/t5/python-questions/how-to-force-python-script-geoprocessing-service/m-p/275908#M21284</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Add a second parameter, datatype Long and type Output. At the end of your script do this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_14134852152942719 jive_text_macro" jivemacro_uid="_14134852152942719" modifiedtitle="true"&gt;
&lt;P&gt;count = int(arcpy.GetCount_management(data_fl)[0])&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;if count &amp;gt; 0:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.arcpy.AddMessage("you have chosen {0} features".format(count))&lt;/P&gt;
&lt;P&gt;else: &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.arcpy.AddMessage("no chosen features")&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;# Set as actual output&lt;/P&gt;
&lt;P&gt;arcpy.SetParameter(1, count)&lt;/P&gt;
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Oct 2014 18:47:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-force-python-script-geoprocessing-service/m-p/275908#M21284</guid>
      <dc:creator>JasonScheirer</dc:creator>
      <dc:date>2014-10-16T18:47:04Z</dc:date>
    </item>
  </channel>
</rss>

