Susan,
You can modify the code for output paramter so there is no result map service returning when the selections result is zero. Here are two options:
(1) If the selections result is zero, set the outputpath of the kernel density path to blank and do not execute the kernel density function. Also, set theoutput parameter as a derived output in the script tool.
Here is the code looks like
import arcpy, os
from arcpy.sa import *
inputval = arcpy.GetParameterAsText(0)
inputpts = r'c:\KernelDensity\data.gdb\Crime'
outputpts = os.path.join(arcpy.env.scratchGDB, "selectcr")
outraster = os.path.join(arcpy.env.scratchGDB, "KernelD_sele1")
query = "ID < " + inputval
arcpy.Select_analysis(inputpts , outputpts, query)
result = arcpy.GetCount_management(outputpts)
count = int(result.getOutput(0))
if count == 0 :
arcpy.AddWarning("count = 0")
outraster = ""
else:
outKDens = KernelDensity(outputpts, "NONE", 45, 1200, "SQUARE_KILOMETERS")
outKDens.save(outraster)
arcpy.SetParameter(1, outraster)
(2) Set the output parameter only when the the selection result is zero. Then set the output paramter as optional in the script tool.
import arcpy, os
from arcpy.sa import *
inputval = arcpy.GetParameterAsText(0)
outraster = arcpy.GetParameterAsText(1)
inputpts = r'c:\KernelDensity\data.gdb\Crime'
outputpts = os.path.join(arcpy.env.scratchGDB, "selectcr")
query = "ID < " + inputval
arcpy.Select_analysis(inputpts , outputpts, query)
result = arcpy.GetCount_management(outputpts)
count = int(result.getOutput(0))
arcpy.AddMessage(" The select count = " + str(count))
if count == 0:
arcpy.AddWarning("count = 0")
arcpy.SetParameter(1, "")
else:
outKDens = KernelDensity(outputpts, "NONE", 45, 1200, "SQUARE_KILOMETERS")
outKDens.save(outraster)