I am trying to write a script tool that will loop through all the disconnected layers in a map document and repoint them using the Layer.replaceDataSource function. When I run the following 3 lines of code:
mxd = arcpy.mapping.MapDocument("CURRENT")
lyr = arcpy.mapping.ListBrokenDataSources(mxd)[0]
lyr.replaceDataSource(r"Database Connections\GISUSER on dep-eia1dbsop01.sde","SDE_WORKSPACE",r"Sample_Location",True)
from the Python Window within ArcGIS Desktop it works fine. But when I put them in a .py file and try to run the script from ArcToolbox it seems to reconnect the file but then removes it from the map document.