<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Bulk upload data to survey 123 in ArcGIS Survey123 Questions</title>
    <link>https://community.esri.com/t5/arcgis-survey123-questions/bulk-upload-data-to-survey-123/m-p/1512924#M58233</link>
    <description>&lt;P&gt;It's been a few years since this was asked, but since I couldn't find good documentation on this, thought I'd share my solution in case someone like me is seeking a way to bulk add records to a Survey123 feature class. ArcPro with append would work but I opted for a Python script and appending an excel file.&lt;/P&gt;&lt;P&gt;A few notes: I had a few issues with some entries that needed to be truncated because they exceeded the 255 or 1000 string limit, so this accounts for that. I also had issues with null values when I first tried using a CSV file (python kept putting "nan" for null) but switching to an XLSX file removed that issue.&amp;nbsp;&lt;/P&gt;&lt;P&gt;With that preamble - here is the Python code I used to bulk add records from an XLSX file to a Survey123 feature class:&lt;BR /&gt;&lt;BR /&gt;&lt;EM&gt;This assumes you have arcgis, pandas, and numpy installed&amp;nbsp;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from arcgis.gis import GIS
from arcgis.features import FeatureLayer
from arcgis.geocoding import geocode
import pandas as pd
import numpy as np
import arcgis.env as env

# Connect to your GIS environment
gis=GIS("https://www.arcgis.com","YOUR USERNAME HERE","PASSWORD")

# Set the active GIS environment
env.active_gis=gis

# Access the feature layer
feature_layer_url="URL TO THE HOSTED FEATURE CLASS"
feature_layer=FeatureLayer(feature_layer_url)

# Load your Excel data
excel_file="EXCEL XLSX FILE WITH FULL PATH"
df=pd.read_excel(excel_file)

# Define the maximum lengths
max_lengths = {
    'organization_name': 255,
    'category': 255,
    'Other_category': 255,
    'program_name': 255,
    'program_details': 1000,
    'eligibility': 1000,
    'website_url': 255,
    'supplementary_website_url': 255,
    'operating_hours': 1000,
    'location': 255,
    'contact_name': 255,
    'contact_email': 255,
    'phone1': 255,
    'extension1': None,  # Assuming extension fields are numeric
    'phone_type1': 255,
    'other_phone1': 255,
    'phone1_details': 255
}

# Function to truncate fields based on max length
def truncate_fields(df, max_lengths):
    for field, max_len in max_lengths.items():
        if max_len is not None:
            if field in df.columns:
                df[field] = df[field].astype(str).apply(lambda x: x[:max_len])
    return df

# Clean and convert data
df = df.fillna('')
df = df.apply(lambda col: col.map(lambda x: None if pd.isna(x) else x))

# Apply truncation
df = truncate_fields(df, max_lengths)

# Convert DataFrame to dictionary
df_dict = df.to_dict(orient="records")

# Function to geocode an address
def geocode_address(address):
    if address:  # Check if address is not empty
        results = geocode(address)
        if results:
            location = results[0]['location']
            return location['x'], location['y']
    return None, None

# Create features from the Excel data
features = []
for record in df_dict:
    x, y = geocode_address(record.get("location"))
    feature = {
        "attributes": record,
        "geometry": {
            "x": x,
            "y": y,
            "spatialReference": {"wkid": 4326} if x is not None and y is not None else None
        } if x is not None and y is not None else None
    }
    features.append(feature)

# Add features to the feature layer
if features:
    response = feature_layer.edit_features(adds=features)
    print(response)
else:
    print("No valid features to add.")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 31 Jul 2024 13:51:09 GMT</pubDate>
    <dc:creator>JamiDennis</dc:creator>
    <dc:date>2024-07-31T13:51:09Z</dc:date>
    <item>
      <title>Bulk upload data to survey 123</title>
      <link>https://community.esri.com/t5/arcgis-survey123-questions/bulk-upload-data-to-survey-123/m-p/1182947#M43252</link>
      <description>&lt;P&gt;Is it possible to upload existing survey data into a Survey 123 survey? We have data from an old survey (not Survey 123) that we wish to store/ combine with data in the Survey 123 survey.&amp;nbsp;&lt;/P&gt;&lt;P&gt;This question was asked in 2018 but I am hoping the answer might be different now.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Jun 2022 23:29:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-survey123-questions/bulk-upload-data-to-survey-123/m-p/1182947#M43252</guid>
      <dc:creator>EveHayden</dc:creator>
      <dc:date>2022-06-14T23:29:37Z</dc:date>
    </item>
    <item>
      <title>Re: Bulk upload data to survey 123</title>
      <link>https://community.esri.com/t5/arcgis-survey123-questions/bulk-upload-data-to-survey-123/m-p/1183077#M43257</link>
      <description>&lt;P&gt;Any suggestions I suggest should be tried on a copy of your data.&lt;/P&gt;&lt;P&gt;is your survey stored as a table or part of a feature class.&lt;/P&gt;&lt;P&gt;If as a table have you tried using Load Data in Catalog.&lt;/P&gt;&lt;P&gt;If a feature class, did it store x,y locations.&amp;nbsp; If so you can generate the points and use Load Data&lt;/P&gt;</description>
      <pubDate>Wed, 15 Jun 2022 11:34:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-survey123-questions/bulk-upload-data-to-survey-123/m-p/1183077#M43257</guid>
      <dc:creator>RobertBorchert</dc:creator>
      <dc:date>2022-06-15T11:34:53Z</dc:date>
    </item>
    <item>
      <title>Re: Bulk upload data to survey 123</title>
      <link>https://community.esri.com/t5/arcgis-survey123-questions/bulk-upload-data-to-survey-123/m-p/1183104#M43258</link>
      <description>&lt;P&gt;I came across this, not too long ago. I haven't tried it yet. Maybe, the procedure could help.&lt;/P&gt;&lt;P&gt;&lt;A href="https://support.esri.com/en/technical-article/000024002" target="_blank"&gt;https://support.esri.com/en/technical-article/000024002&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Jun 2022 13:16:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-survey123-questions/bulk-upload-data-to-survey-123/m-p/1183104#M43258</guid>
      <dc:creator>Alena</dc:creator>
      <dc:date>2022-06-15T13:16:54Z</dc:date>
    </item>
    <item>
      <title>Re: Bulk upload data to survey 123</title>
      <link>https://community.esri.com/t5/arcgis-survey123-questions/bulk-upload-data-to-survey-123/m-p/1183120#M43260</link>
      <description>&lt;P&gt;Use ArcPro and then the Append tool.&amp;nbsp; In pro you can use services in all the tools so just add the hosted layer and Append.&amp;nbsp; Super easy.&lt;/P&gt;&lt;P&gt;I would not use Load Data as it does not handle transformations and such.&lt;/P&gt;</description>
      <pubDate>Wed, 15 Jun 2022 14:36:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-survey123-questions/bulk-upload-data-to-survey-123/m-p/1183120#M43260</guid>
      <dc:creator>DougBrowning</dc:creator>
      <dc:date>2022-06-15T14:36:33Z</dc:date>
    </item>
    <item>
      <title>Re: Bulk upload data to survey 123</title>
      <link>https://community.esri.com/t5/arcgis-survey123-questions/bulk-upload-data-to-survey-123/m-p/1512924#M58233</link>
      <description>&lt;P&gt;It's been a few years since this was asked, but since I couldn't find good documentation on this, thought I'd share my solution in case someone like me is seeking a way to bulk add records to a Survey123 feature class. ArcPro with append would work but I opted for a Python script and appending an excel file.&lt;/P&gt;&lt;P&gt;A few notes: I had a few issues with some entries that needed to be truncated because they exceeded the 255 or 1000 string limit, so this accounts for that. I also had issues with null values when I first tried using a CSV file (python kept putting "nan" for null) but switching to an XLSX file removed that issue.&amp;nbsp;&lt;/P&gt;&lt;P&gt;With that preamble - here is the Python code I used to bulk add records from an XLSX file to a Survey123 feature class:&lt;BR /&gt;&lt;BR /&gt;&lt;EM&gt;This assumes you have arcgis, pandas, and numpy installed&amp;nbsp;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from arcgis.gis import GIS
from arcgis.features import FeatureLayer
from arcgis.geocoding import geocode
import pandas as pd
import numpy as np
import arcgis.env as env

# Connect to your GIS environment
gis=GIS("https://www.arcgis.com","YOUR USERNAME HERE","PASSWORD")

# Set the active GIS environment
env.active_gis=gis

# Access the feature layer
feature_layer_url="URL TO THE HOSTED FEATURE CLASS"
feature_layer=FeatureLayer(feature_layer_url)

# Load your Excel data
excel_file="EXCEL XLSX FILE WITH FULL PATH"
df=pd.read_excel(excel_file)

# Define the maximum lengths
max_lengths = {
    'organization_name': 255,
    'category': 255,
    'Other_category': 255,
    'program_name': 255,
    'program_details': 1000,
    'eligibility': 1000,
    'website_url': 255,
    'supplementary_website_url': 255,
    'operating_hours': 1000,
    'location': 255,
    'contact_name': 255,
    'contact_email': 255,
    'phone1': 255,
    'extension1': None,  # Assuming extension fields are numeric
    'phone_type1': 255,
    'other_phone1': 255,
    'phone1_details': 255
}

# Function to truncate fields based on max length
def truncate_fields(df, max_lengths):
    for field, max_len in max_lengths.items():
        if max_len is not None:
            if field in df.columns:
                df[field] = df[field].astype(str).apply(lambda x: x[:max_len])
    return df

# Clean and convert data
df = df.fillna('')
df = df.apply(lambda col: col.map(lambda x: None if pd.isna(x) else x))

# Apply truncation
df = truncate_fields(df, max_lengths)

# Convert DataFrame to dictionary
df_dict = df.to_dict(orient="records")

# Function to geocode an address
def geocode_address(address):
    if address:  # Check if address is not empty
        results = geocode(address)
        if results:
            location = results[0]['location']
            return location['x'], location['y']
    return None, None

# Create features from the Excel data
features = []
for record in df_dict:
    x, y = geocode_address(record.get("location"))
    feature = {
        "attributes": record,
        "geometry": {
            "x": x,
            "y": y,
            "spatialReference": {"wkid": 4326} if x is not None and y is not None else None
        } if x is not None and y is not None else None
    }
    features.append(feature)

# Add features to the feature layer
if features:
    response = feature_layer.edit_features(adds=features)
    print(response)
else:
    print("No valid features to add.")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 31 Jul 2024 13:51:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-survey123-questions/bulk-upload-data-to-survey-123/m-p/1512924#M58233</guid>
      <dc:creator>JamiDennis</dc:creator>
      <dc:date>2024-07-31T13:51:09Z</dc:date>
    </item>
  </channel>
</rss>

