Skip to content
This repository has been archived by the owner on Mar 31, 2020. It is now read-only.

Ability to 'Replace' Item and keep Feature Service ID. #296

Open
delfavero opened this issue Sep 19, 2016 · 2 comments
Open

Ability to 'Replace' Item and keep Feature Service ID. #296

delfavero opened this issue Sep 19, 2016 · 2 comments

Comments

@delfavero
Copy link

ArcRest 3.5.3
Enhancement

I am working on a script to custom update a Survey123 xml form with updated choices lists from a SQL database.

After modifying the form based on the database, I cannot see a way to simply replace the xml file in AGOL and keep the same FSID.

The attached script adds a new form with the same name to the folder with a new FSID. I am attempting to use AddItem. Should I use UpdateItem?

syncForms3_ReplacePortalXML_py.txt

from arcpy import AddMessage
import os, arcrest

from syncForms1_listFormFSIDs import listFSIDs

formsFolder = r'C:\Users\sdelfavero\ArcGIS\My Survey Designs'

portalURL = 'https://nps.maps.arcgis.com'

fsIDs = listFSIDs(formsFolder)[0]

fsIDs = {'Bear Patrols' : 'e0dd349f25134112af9677c7db38a683'}
creds = {'user' : 'xxx', 'pw' : 'xxx'}

def msg(txt):
print (txt)
AddMessage(txt)

def listXMLs():

XMLs = {}

for pth, dirs, fNames in arcpy.da.Walk(formsFolder):

for fName in fNames:

if fName.endswith('.xml'):

x = os.path.join(pth, fName)

print x

XMLs[fName] = x

return XMLs

def createSecurityHH():
# create security dictionary object
msg('\nCreating Security Handler')
user = creds['user']
pw = creds['pw']
sh = arcrest.AGOLTokenSecurityHandler(username=user,
password=pw,
org_url=portalURL)
return sh

def replaceXML(sh, srv, xml, fsID):

portalAdmin = arcrest.manageorg.Administration(securityHandler=sh)
content = portalAdmin.content
item1 = content.getItem(itemId=fsID)
users = content.users
user = users.user()
fldr = 'Survey-' + srv
user.currentFolder = fldr

itemParams = arcrest.manageorg.ItemParameter()
itemParams.title = srv
itemParams.type = "Form"
itemParams.overwrite = True
itemParams.typeKeywords = [u'Form', u'Survey123', u'xForm']
itemParams.thumbnail = xml.replace('.xml', '.png')

item = user.addItem(
    itemParameters=itemParams,
    filePath= xml,
    overwrite=True)
print item.title + " created"

def replaceAllXMLs():
msg('Updating All Forms in ArcGIS Online')
sh = createSecurityHH()

for srv in fsIDs:
    fsID = fsIDs[srv]
    xml = os.path.join(formsFolder, fsID, srv + '.xml')
    print '\nReplacing: ' + srv
    print ' ~FSID = ' + fsID
    replaceXML(sh, srv, xml, fsID)

if name == 'main':
replaceAllXMLs()

@MikeMillerGIS
Copy link
Member

I have not looked into how the survey 123 configuration is stored. Can you break it down into the items that are required? I know there is a feature service, is there another item you are trying to update? The feature service includes domains, you probably would need to change them to update a picklist

@tedrick
Copy link
Member

tedrick commented Aug 1, 2017

@delfavero - Survey123 Form items are zip files, not XML. Aside form the xForm XML, it may also include CSV files for other choice lists / data lookups, images, audio. (though not necessary, it also includes the xlsx file as well). As it happens, we (the Survey123 team) are working on a script to enable this workflow (we're primarily looking to support CSV replacement, but it should be able to support the XML file as well, so long as it's been properly formatted).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants