Let me say more about this...
I've reduced the code down to show the basic process, without making it too simplified.
In this reduced example code, I've ripped out all the code that uses a couple other Python modules that are in the actual production code: pymssql (to pull data from our SQL server database), and openpyxl (to update an excel spreadsheet with more data about the results of the code running). Also gutted out is code that detects if data from a previous run of the tool exists, in which case it deletes it before continuing on to to the actual processing.
Herewith:
import arcpy
import os
import getpass
# save the current workspace
save_workspace = arcpy.env.workspace
# get the current user's login id
run_user = getpass.getuser()
# get 3 parameter values
ex_district = int(arcpy.GetParameterAsText(0))
ex_year = int(arcpy.GetParameterAsText(1))
ex_num = int(arcpy.GetParameterAsText(2))
# this is where the 'raw' data is coming from
data_source = r"N:\gis-files\merged.gdb\raw"
# this where the prepared data is going to
destination_gdb_directory = r"N:\shared\George"
destination_gdb_name = "ex_gdb.gdb"
arcpy.CreateFileGDB_management(destination_gdb_directory,destination_gdb_name)
# set the workspace to this destination GDB
arcpy.env.workspace = os.path.join(destination_gdb_directory,destination_gdb_name)
# create a new feature class in the destination GDB
estination_feature_class = "example_results"
destination_feature_template = r"MAIN\Reports\Reports (polygons)"
arcpy.CreateFeatureclass_management(arcpy.env.workspace,destination_feature_class,"POLYGON",destination_feature_template,"SAME_AS_TEMPLATE","SAME_AS_TEMPLATE",destination_feature_template)
# create some kind of 'layer' that is a selection of the 'raw' data
ex_where = "(REGION={0} AND YEAR={1} AND NUM={2})".format(ex_district,ex_year,ex_num)
ex_data_select = "example_data_select"
arcpy.MakeFeatureLayer_management(data_source,ex_data_select,ex_where)
# copy the selected features out of the 'raw' data
ex_data_copied = "example_data_copied"
arcpy.CopyFeatures_management(ex_data_select,ex_data_copied)
# dissolve them into 1 feature
ex_data_dissolved = "example_data_dissolved"
arcpy.Dissolve_management(ex_data_copied,ex_data_dissolved,"","","MULTI_PART")
# cut that feature up by county boundary
ex_data_intersected = "example_data_intersected"
ex_intersect_inputs = [ex_data_dissolved, 'Basemap\\County outlines']
arcpy.Intersect_analysis(ex_intersect_inputs,ex_data_intersected,"ALL", "", "INPUT")
# add features to the prepared data with our attributes
from_shape_field = arcpy.Describe(ex_data_intersected).ShapeFieldName
to_shape_field = arcpy.Describe(destination_feature_class).ShapeFieldName
copy_from = arcpy.SearchCursor(ex_data_intersected)
insert_to = arcpy.InsertCursor(destination_feature_class)
for from_row in copy_from:
new_row = insert_to.newRow() # create empty record
new_row.setValue(to_shape_field,from_row.getValue(from_shape_field)) # copy geometry
new_row.setValue('DocNo',ex_num) # put in source document number
new_row.setValue('OtherID',from_row.getValue('NAME')) # copy county name
new_row.setValue('DigBy',getpass.getuser()) # put in user name
insert_to.insertRow(new_row) # add feature to final destination
del new_row
del copy_from
del insert_to
# load the destination_feature_class into the user's map TOC
new_map_layer = "Your Results"
arcpy.MakeFeatureLayer_management(destination_feature_class,new_map_layer)
this_mxd = arcpy.mapping.MapDocument("CURRENT")
this_frame = arcpy.mapping.ListDataFrames(this_mxd)[0]
this_layer = arcpy.mapping.Layer(new_map_layer)
arcpy.mapping.AddLayer(this_frame,this_layer,"TOP")
# restore the prior workspace
arcpy.env.workspace = save_workspace
(let me know if the Python code snippet didn't paste in correctly above)
This is run as a script tool in a 'plain' toolbox (not a 'Python toolbox'). On my 10.2 installation it works like a charm. The only layer that gets added to my map is the one at the end and it shows up at the top of the TOC as 'Your Results'. And it contains the correct data. Yay!
Now... for the interesting part ...
I log in, as me, on a different machine that's installed with 10.1 and I run this tool and it also works as expected. Grnpph. So... either:
1) in simplifying the code for example/discussion purposes I inadvertently fixed the problem or removed problem-causing code;
or
2) something about the profile of the usual user is causing it to bomb out. The usual user of this tool has left for the day and I can't log in as them to try it out under their login today. I'll try it out with them the next time they're in and available.