Hi, I’m new to FME, looking to setup a python caller to manipulate some feature services on our Enterprise portal.
Is it possible to call feature services from within a python caller inside a workspace hosted by FME Flow?
The script below works fine in FME Workbench and prints True, the FME Flow prints false.
import fme
import fmeobjects
import arcpy
from arcgis.gis import GIS
from arcgis.features import FeatureLayer
def ProcessWebhook(feature):
# URL to AGOL or Portal
url_gis = "https://<servername>/portal" # URL to AGOL or Portal
user = "xxxx" # AGOL or Portal username
pwd = "xxxx" # user password
gis = GIS(url_gis, user, pwd)
id = feature.getAttribute('webhook_feat_id')
whereclause = 'field_3 = ' + "'" + str(id) + "'"
in_feat_url = r"https://<servername>/hostedserver/rest/services/Hosted/service_3c55880fb4112b08f2af29c22e/FeatureServer/0"
in_feat_fl = FeatureLayer(in_feat_url)
in_feat = in_feat_fl.url
out_feat_url = r"https://<servername>/server/rest/services/Test/Form1/FeatureServer/0"
out_feat_fl = FeatureLayer(out_feat_url)
out_feat = out_feat_fl.url
# check that feature services are available
if all(arcpy.Exists(lyr) for lyr in in_feat, out_feat]):
in_feat_sel = arcpy.management.SelectLayerByAttribute(
in_layer_or_view=in_feat,
selection_type="NEW_SELECTION",
where_clause=whereclause,
invert_where_clause=None
)
arcpy.management.Append(
inputs=in_feat_sel,
target=out_feat,
schema_type="NO_TEST",
field_mapping="",
subtype="",
expression="",
match_fields=None,
update_geometry="NOT_UPDATE_GEOMETRY"
)
print(True)
else:
print(False)
Thanks for any pointers.
Regards,
Elliott