POST
|
Thanks @TonyAlmeida but that didn't solved my issue. I also tried to create a function just for the query definition that didn't help either. So I ended up splitting the code into 2 scripts: Step 1 create the query definition, Step2 update the layouts and PDF. Using a Mode Builder I can run both scripts at the same time and no issue. I would love to get the code to run into 1 script but whatever works for now. Thanks! below was my revised code with the definition query function: import arcpy
import os
import sys
from arcgis import GIS
from datetime import datetime
# Get today's date
today = datetime.today()
formatted_date = today.strftime("%m%d%Y")
#********************************************************************************************
def GRDefinitionQuery(MapName,LayerName,FieldNumber,LayoutName):
newDefinitionQueryString = "SAG_FieldNumber = "+FieldNumber
arcpy.AddMessage(newDefinitionQueryString)
m= aprx.listMaps(MapName)[0]
arcpy.AddMessage(MapName)
for lyr in m.listLayers():
arcpy.AddMessage(lyr.name)
if lyr.name ==LayerName:
arcpy.AddMessage("We found our layer to update")
if lyr.supports('DefinitionQuery'):
arcpy.AddMessage("here we go")
# Updade Definition query
dql = lyr.listDefinitionQueries()
arcpy.AddMessage("original dql" + str(dql))
for dq in dql:
arcpy.AddMessage("in dq")
dq['sql'] = newDefinitionQueryString
lyr.updateDefinitionQueries(dql)
arcpy.AddMessage("revised dql" + str(dql))
count_result = arcpy.management.GetCount(lyr)
record_count = int(count_result[0])
arcpy.AddMessage("number of records: " + str(record_count))
break
aprx.save()
time.sleep(5) # Small delay
def GRMapExtent(MapName,LayerName,FieldNumber,FieldName, LayoutName):
map_name = MapName
arcpy.AddMessage(" " +map_name)
layer_name = LayerName
map_frame_name = 'Map Frame'
# Access the map
map_obj = aprx.listMaps(map_name)[0]
# Clear any existing selection
for lyr in map_obj.listLayers():
if lyr.isFeatureLayer:
lyr.setSelectionSet(None)
# Get the layer
layer = map_obj.listLayers(layer_name)[0]
# Use arcpy.Describe to get extent
desc = arcpy.Describe(layer)
layer_extent = desc.extent
count_result = arcpy.management.GetCount(layer)
record_count = int(count_result[0])
arcpy.AddMessage(" number of records: " + str(record_count))
# Access the layout and map frame
layout = aprx.listLayouts(LayoutName)[0] # or specify layout by name: aprx.listLayouts("LayoutName")[0]
map_frame = layout.listElements("mapframe_element", map_frame_name)[0]
cursor = arcpy.da.SearchCursor(layer, ['SHAPE@',FieldNumber,FieldName])
arcpy.AddMessage("*****************")
for c in cursor:
arcpy.AddMessage(u' {0},{1}'.format(c[1],c[2]))
strName = c[2]
arcpy.AddMessage(" Final Name: " + str(strName))
extent = c[0].extent
paddingFirst = extent.XMax-extent.XMin
padding = (float(paddingFirst)/float(20))
new_extent=arcpy.Extent(extent.XMin-padding,extent.YMin-padding,extent.XMax+padding,extent.YMax+padding,None,None,None,None,extent.spatialReference)
# Set the map frame extent to the layer extent
map_frame.camera.setExtent(new_extent)
arcpy.AddMessage(" " +"Mainframe extent done")
GRLayoutTitle(SAGFieldNunber + " : "+strName+ " "+ l)
arcpy.AddMessage(" " +"Title update")
GRExportLayouttoPDF(template_name,strName,formatted_date)
arcpy.AddMessage(" " +"Export to PDF done")
#sys.exit(0)
def GRLayoutTitle(TitleName):
elm_name = "SAG Title" # the name you assign to the title (TEXT) element
p = arcpy.mp.ArcGISProject("CURRENT")
for lyt in p.listLayouts(): # get the element
for elm in lyt.listElements("TEXT_ELEMENT"):
if elm.name == elm_name:
elm.text = TitleName
def GRExportLayouttoPDF(layoutName,FieldName, strDate):
layout_name = layoutName # Name of the layout in your project
output_folder= r"C:\temp"
output_name = layoutName+"_"+FieldName+"_"+strDate+".pdf"
layout = aprx.listLayouts(layout_name)[0]
layout.exportToPDF(output_folder+"\\"+output_name, resolution=150) #,jpeg_compression_quality=80, output_as_image=True,compress_vector_graphics=True
#********************************************************************************************
arcpy.AddMessage("Let's update the Definition queries")
aprx = arcpy.mp.ArcGISProject("CURRENT")
LyrName = arcpy.GetParameterAsText(0)
FieldName = arcpy.GetParameterAsText(1)
name_field = 'SAG_FieldNumber' #'SAG_SiteName'
SAGFieldNunber = arcpy.GetParameterAsText(2)
SAGFieldName = 'SAG_FieldName'
listMaps = ['2021 Ortho','2023 Ortho','LIDAR']
for l in listMaps:
arcpy.AddMessage(l + "-------------------------------------------")
NewMapName = "SAG_Manure_Map_"+l
template_name = "SAG_Manure_Layout_"+l
arcpy.AddMessage("Now let's change the Query Definituon")
GRDefinitionQuery(NewMapName,LyrName, SAGFieldNunber,template_name)
arcpy.AddMessage("Now let's change the extent of the map")
GRMapExtent(NewMapName, LyrName,name_field,SAGFieldName,template_name)
arcpy.AddMessage("------------------------")
arcpy.AddMessage("Definition query updated")
... View more
07-14-2025
08:23 PM
|
0
|
0
|
197
|
POST
|
Hello, I created a script that loop through 3 maps, update a definition query based on a parameter then change the extent of the layout and export the layout to PDF. It's "kind of working" however, every time I run the process ONE map (never the same) get stuck on the extent of the previous selection. Below is the code and the details info the process. Weird thing is if I look in all 3 maps, the query definition has been updated... import arcpy
import os
import sys
from arcgis import GIS
from datetime import datetime
# Get today's date
today = datetime.today()
formatted_date = today.strftime("%m%d%Y")
#********************************************************************************************
def GRMapExtent(MapName,LayerName,FieldNumber,FieldName, LayoutName):
map_name = MapName
arcpy.AddMessage(" " +map_name)
layer_name = LayerName
map_frame_name = 'Map Frame'
# Access the map
map_obj = aprx.listMaps(map_name)[0]
# Get the layer
layer = map_obj.listLayers(layer_name)[0]
# Use arcpy.Describe to get extent
desc = arcpy.Describe(layer)
layer_extent = desc.extent
count_result = arcpy.management.GetCount(layer)
record_count = int(count_result[0])
arcpy.AddMessage(" number of records: " + str(record_count))
# Access the layout and map frame
layout = aprx.listLayouts(LayoutName)[0] # or specify layout by name: aprx.listLayouts("LayoutName")[0]
map_frame = layout.listElements("mapframe_element", map_frame_name)[0]
cursor = arcpy.da.SearchCursor(layer, ['SHAPE@',FieldNumber,FieldName])
arcpy.AddMessage("*****************")
for c in cursor:
arcpy.AddMessage(u' {0},{1}'.format(c[1],c[2]))
strName = c[2]
arcpy.AddMessage(" Final Name: " + str(strName))
extent = c[0].extent
paddingFirst = extent.XMax-extent.XMin
padding = (float(paddingFirst)/float(20))
new_extent=arcpy.Extent(extent.XMin-padding,extent.YMin-padding,extent.XMax+padding,extent.YMax+padding,None,None,None,None,extent.spatialReference)
# Set the map frame extent to the layer extent
map_frame.camera.setExtent(new_extent)
arcpy.AddMessage(" " +"Mainframe extent done")
GRLayoutTitle(SAGFieldNunber + " : "+strName+ " "+ l)
arcpy.AddMessage(" " +"Title update")
GRExportLayouttoPDF(template_name,strName,formatted_date)
arcpy.AddMessage(" " +"Export to PDF done")
#sys.exit(0)
def GRLayoutTitle(TitleName):
elm_name = "SAG Title" # the name you assign to the title (TEXT) element
p = arcpy.mp.ArcGISProject("CURRENT")
for lyt in p.listLayouts(): # get the element
for elm in lyt.listElements("TEXT_ELEMENT"):
if elm.name == elm_name:
elm.text = TitleName
def GRExportLayouttoPDF(layoutName,FieldName, strDate):
layout_name = layoutName # Name of the layout in your project
output_folder= r"C:\GIS\OUTPUT_PDF"
output_name = layoutName+"_"+FieldName+"_"+strDate+".pdf"
layout = aprx.listLayouts(layout_name)[0]
layout.exportToPDF(output_folder+"\\"+output_name, resolution=200)
#********************************************************************************************
arcpy.AddMessage("Let's update the Definition queries")
aprx = arcpy.mp.ArcGISProject("CURRENT")
LyrName = arcpy.GetParameterAsText(0)
FieldName = arcpy.GetParameterAsText(1)
name_field = 'SAG_FieldNumber' #'SAG_SiteName'
SAGFieldNunber = arcpy.GetParameterAsText(2)
SAGFieldName = 'SAG_FieldName'
listMaps = ['2021 Ortho','2023 Ortho','LIDAR']
for l in listMaps:
arcpy.AddMessage(l + "-------------------------------------------")
NewMapName = "SAG_Manure_Map_"+l
template_name = "SAG_Manure_Layout_"+l
newDefinitionQueryString = "SAG_FieldNumber = "+SAGFieldNunber
arcpy.AddMessage(newDefinitionQueryString)
m= aprx.listMaps(NewMapName)[0]
arcpy.AddMessage(NewMapName)
for lyr in m.listLayers():
arcpy.AddMessage(lyr.name)
if lyr.name ==LyrName:
arcpy.AddMessage("We found our layer to update")
if lyr.supports('DefinitionQuery'):
arcpy.AddMessage("here we go")
# Updade Definition query
dql = lyr.listDefinitionQueries()
arcpy.AddMessage("original dql" + str(dql))
for dq in dql:
arcpy.AddMessage("in dq")
dq['sql'] = newDefinitionQueryString
lyr.updateDefinitionQueries(dql)
arcpy.AddMessage("revised dql" + str(dql))
count_result = arcpy.management.GetCount(lyr)
record_count = int(count_result[0])
arcpy.AddMessage("number of records: " + str(record_count))
arcpy.AddMessage("Now let's change the extent of the map")
GRMapExtent(NewMapName, LyrName,name_field,SAGFieldName,template_name)
arcpy.AddMessage("------------------------")
arcpy.AddMessage("Definition query updated") This is the details from the proces I looked at this for too long:( Any help would be much appreciated
... View more
07-13-2025
04:58 PM
|
1
|
3
|
267
|
POST
|
Hello, I ma trying to automate the process of creating/updating AGOL items metadata using Survey123, FME, etc... I would like to know where can I get the list of values for all the dropdown list used in the AGOL Metadata editor (see example below) without having to test them all individually 😁 Value in XML file: Any help would be much apprecited. Thanks! Dominic
... View more
06-11-2025
08:07 AM
|
1
|
1
|
195
|
POST
|
@Neal_t_k and @ChristopherCounsell Thank you both for all the inputs. As I mentioned before, I am trying to minimize the number of fields in the feature class. So I tested adding a true field for the dropdown list.... everything is working fine EXCEPT if I select the Other option. ex: Original WEI_BMS field has value of JSON, I update the data using the dropdown field (WEI_DBMS_List) to Shapefile and Submit.... both fields have the Shapefile value If original WEI_BMS field has value of Shapefile, I update the data using the dropdown field (WEI_DBMS_List) to Other ... then I get the option to add a new value: let's say I add KMZ and Submit.... WEI_BMS field will have KMZ and the new WEI_DBMS_List field will have Other has a value. I added a pulldata formula in the Calculate and if I click Recalculate I will get the JSON there. I don't want users to have to click to refresh the data. So how could I pass the WEI_DBMS value to the dropdown list if the value is Other? I tried coalesce and if statement and both of them create an error with the parsing.
... View more
05-29-2025
11:23 AM
|
0
|
1
|
462
|
POST
|
it just make the survey too cluttered.. my users will get confused with this interface. I would probably need 2 surveys: One for initial data entry and one for data editing.
... View more
05-28-2025
11:53 AM
|
0
|
1
|
911
|
POST
|
@Neal_t_k , I don't think this is going to work as the calculation over write the existing value with the coalesce formula. I am probably going to need an IF statement there instead...
... View more
05-28-2025
09:31 AM
|
0
|
3
|
942
|
POST
|
Hi @ChristopherCounsell Yes, I have 2 "dummy" fields as NULL used as place holder (one for the dropdown list and one for the "Other" option). I do not want to created true fields has I want to use this process for the entire survey and I have about 10 questions with dropdown list. The current process work GREAT if I create a new entry from scratch. How could I make use of the search functionality to populate a dropdown using live data from the map service, with an Other option in case of a new value for that dropdown and retain the existing value.... all that without having to create 2 extra fields in the layer. Thanks!
... View more
05-28-2025
08:03 AM
|
0
|
11
|
953
|
POST
|
Hello, I am following the steps from this post Open List and it's working fine to ge my unique list of values in the dropdown list https://community.esri.com/t5/arcgis-survey123-blog/survey123-tricks-of-the-trade-open-lists/ba-p/1180879 However, when I Edit the survey, I "loose" the original value that was entered. How can I retain the original value when I am in edit mode? - I've tried Calculated field , not working Attached the section of the spreadsheet showing above. The process is working fine with CSVs... I just would like to be able to use the "live" data from the map service as users start to add more options for each dropdowns. Any help or suggestions would be much appreciated. Thanks!
... View more
05-27-2025
02:49 PM
|
0
|
16
|
1561
|
POST
|
well I know that, I enabled feature access on the feature service with the following options: I have the fields in the the feature service with values: If I don't add them to the survey, they are not returned in the payload. I just need then hidden (or I could probably do with read only)
... View more
05-08-2025
08:35 AM
|
0
|
0
|
588
|
POST
|
well... never assume the obvious.... One issue was that the date fields were NOT included in the Survey (my bad I should have checked that first..I am taking over from a co-worker).... But now, when I try to add these fields in the survey (read only) I get the following: I did enabled all the options listed above , but still no go. @j-bromp , how to you have the Created_date field setup in the Survey Connect?
... View more
05-08-2025
08:12 AM
|
0
|
3
|
605
|
POST
|
ok, but I also have other DATE fields (not system fields) and those are not coming either
... View more
05-02-2025
07:06 AM
|
0
|
0
|
717
|
POST
|
Hi, I am using FME to pull payload from a webhook setup on Survey123. Everything is working fine, however, no DATE fields are returned in the payload: below is the payload returned {
"applyEdits" : [
{
"id" : 0,
"updates" : [
{
"attributes" : {
"status" : "Assigned",
"assignedto" : "BLABLABLA",
"globalid" : "e1c4c605-c4f1-4be0-8669-3d064abb2ea4",
"OBJECTID" : 45
}
}
]
}
],
"feature" : {
"attributes" : {
"actyear" : 25,
"actidint" : 6,
"actid" : "GRM2500006",
"actcategory" : "Solutions",
"acttype" : "Update GIS solution or application",
"details" : "test",
"urgent" : "No",
"urgent_details" : null,
"division" : "Administrative Services",
"bureau" : "Human Resources",
"plannedstartdt" : null,
"plannedenddt" : null,
"plannedeffort" : 0,
"status" : "Assigned",
"assignedto" : "BLABLABLA",
"actualenddt" : null,
"pocname" : "ESRI GISResourceMgmt",
"pocemail" : "aBLABLABLA",
"capabilities" : "Under Review",
"orggoal" : "Under Review",
"corepillar" : "Under Review",
"prggoal" : "Under Review",
"strategicaction" : null,
"frameworkpillar" : null,
"globalid" : "e1c4c605-c4f1-4be0-8669-3d064abb2ea4",
"OBJECTID" : 45
},
"geometry" : null,
"layerInfo" : {
"id" : 0,
"name" : "GIS_Activities",
"type" : "Feature Layer",
"globalIdField" : "globalid",
"objectIdField" : "OBJECTID",
"relationships" : [
{
"id" : 0,
"name" : "Effort",
"relatedTableId" : 2,
"cardinality" : "esriRelCardinalityOneToMany",
"role" : "esriRelRoleOrigin",
"keyField" : "globalid",
"composite" : true
},
{
"id" : 1,
"name" : "Comments",
"relatedTableId" : 1,
"cardinality" : "esriRelCardinalityOneToMany",
"role" : "esriRelRoleOrigin",
"keyField" : "globalid",
"composite" : true
}
]
},
"result" : {
"globalId" : "e1c4c605-c4f1-4be0-8669-3d064abb2ea4",
"objectId" : 45,
"uniqueId" : 45,
"success" : true
},
"attachments" : null
},
"eventType" : "editData"
} Data in So, what am I missing? Thanks for any input
... View more
05-02-2025
06:43 AM
|
0
|
9
|
729
|
POST
|
Hello I am creating a data expression in dashboard, trying to convert data fields (from Central Time to UTC). When I look at the individual features, it's working, everything looks like I want it. However, when I push to the featureset to be used in a table , ALL the date fields have the same values... What am I doing wrong? Thanks! var portal = Portal('https://www.arcgis.com');
var fs = FeatureSetByPortalItem(
portal,
'1b32fd673de04b16b15bf5a923b7d1fb',
0,
[
'dr_DateTime',
'dr_DateText'
],
false
);
// return fs
var features = [];
var feat;
// Populate feature array
for (var f in fs) {
feat = {
'attributes': {
'dr_DateTimeMd': ChangeTimeZone(f['dr_DateTime'],"+06:00"),
'dr_DateTimeF': f['dr_DateTime'],
'dr_DateTimeUTCF': ToUTC(f['dr_DateTime']),
'dr_DateTextF': f['dr_DateText']
}}
Push(features, feat);
};
// return features
var dowDict = {
'fields': [
{'name': 'dr_DateTimeMd', 'type': 'esriFieldTypeDate'},
{'name': 'dr_DateTimeF', 'type': 'esriFieldTypeDate'},
{'name': 'dr_DateTimeUTCF', 'type': 'esriFieldTypeDate'},
{'name': 'dr_DateTextF', 'type': 'esriFieldTypeString'}
],
'geometryType': '',
'features': features
};
// Convert dictionary to feature set.
var fs_dict = FeatureSet(dowDict);
return fs_dict raw featureset Each individual features: Final featureset
... View more
03-25-2025
07:58 AM
|
0
|
0
|
181
|
POST
|
I unchecked the "Enable Sync" and everything started to work just fine.
... View more
02-27-2025
09:50 AM
|
0
|
0
|
440
|
POST
|
Hello I have an AGOL feature layer (published from ArcGIS Pro) and for some reason I can' get the Pipeline the Replace to work it's a very basic flow: Pushing data from Portal to AGOL I keep getting this message: The selected layer does not support the truncate operation Feature service settings: Could it be that's because I have a VIEW related to that feature service? I have another flow very similar (target is an AGOL native feature service) no VIEWs and the Pipeline works just fine Both targets have "supportsTruncate" : false, so I don't think it's the issue. Any ideas? Thanks!
... View more
02-27-2025
08:13 AM
|
1
|
2
|
481
|
Title | Kudos | Posted |
---|---|---|
1 | 06-11-2025 08:07 AM | |
1 | 07-13-2025 04:58 PM | |
1 | 02-27-2025 08:13 AM | |
1 | 11-05-2024 06:51 AM | |
2 | 09-18-2024 07:44 AM |
Online Status |
Offline
|
Date Last Visited |
Friday
|