{"action":"opened","issue":{"url":"https://api.github.com/repos/Esri/Survey123Community/issues/559","repository_url":"https://api.github.com/repos/Esri/Survey123Community","labels_url":"https://api.github.com/repos/Esri/Survey123Community/issues/559/labels{/name}","comments_url":"https://api.github.com/repos/Esri/Survey123Community/issues/559/comments","events_url":"https://api.github.com/repos/Esri/Survey123Community/issues/559/events","html_url":"https://github.com/Esri/Survey123Community/issues/559","id":177928858,"number":559,"title":"Using ArcREST module to replace XML form on AGOL ","user":{"login":"delfavero","id":17815304,"avatar_url":"https://avatars.githubusercontent.com/u/17815304?v=3","gravatar_id":"","url":"https://api.github.com/users/delfavero","html_url":"https://github.com/delfavero","followers_url":"https://api.github.com/users/delfavero/followers","following_url":"https://api.github.com/users/delfavero/following{/other_user}","gists_url":"https://api.github.com/users/delfavero/gists{/gist_id}","starred_url":"https://api.github.com/users/delfavero/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/delfavero/subscriptions","organizations_url":"https://api.github.com/users/delfavero/orgs","repos_url":"https://api.github.com/users/delfavero/repos","events_url":"https://api.github.com/users/delfavero/events{/privacy}","received_events_url":"https://api.github.com/users/delfavero/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-09-19T23:57:40Z","updated_at":"2016-09-19T23:57:40Z","closed_at":null,"body":"Below is a script to replace the form, but instead it creates an identically named copy. \r\n\r\nAny advice on getting this to work would be much appreciated.\r\n\r\nfrom arcpy import AddMessage\r\nimport os, arcrest \r\n##from syncForms1_listFormFSIDs import listFSIDs\r\n\r\n##formsFolder = r'C:\\Users\\sdelfavero\\ArcGIS\\My Survey Designs'\r\nportalURL = 'https://nps.maps.arcgis.com'\r\n\r\n##fsIDs = listFSIDs(formsFolder)[0]\r\nfsIDs = {'Bear Patrols' : 'e0dd349f25134112af9677c7db38a683'}\r\ncreds = {'user' : 'xxx', 'pw' : 'xxx'}\r\n\r\ndef msg(txt):\r\n    print (txt)\r\n    AddMessage(txt)\r\n\r\n##def listXMLs():\r\n##    XMLs = {}\r\n##    for pth, dirs, fNames in arcpy.da.Walk(formsFolder):\r\n##        for fName in fNames:\r\n##            if fName.endswith('.xml'):\r\n##                x = os.path.join(pth, fName)\r\n##                print x\r\n##                XMLs[fName] = x\r\n##                return XMLs\r\n                \r\ndef createSecurityHH():\r\n    # create security dictionary object\r\n    msg('\\nCreating Security Handler')\r\n    user = creds['user']\r\n    pw = creds['pw']\r\n    sh = arcrest.AGOLTokenSecurityHandler(username=user,\r\n                                          password=pw,\r\n                                          org_url=portalURL)\r\n    return sh\r\n                                          \r\ndef replaceXML(sh, srv, xml, fsID):\r\n\r\n    portalAdmin = arcrest.manageorg.Administration(securityHandler=sh)\r\n    content = portalAdmin.content\r\n    item1 = content.getItem(itemId=fsID)\r\n    users = content.users\r\n    user = users.user()\r\n    fldr = 'Survey-' + srv\r\n    user.currentFolder = fldr\r\n    \r\n    itemParams = arcrest.manageorg.ItemParameter()\r\n    itemParams.title = srv\r\n    itemParams.type = \"Form\"\r\n    itemParams.overwrite = True\r\n    itemParams.typeKeywords = [u'Form', u'Survey123', u'xForm']\r\n    itemParams.thumbnail = xml.replace('.xml', '.png')\r\n    \r\n    item = user.addItem(\r\n        itemParameters=itemParams,\r\n        filePath= xml,\r\n        overwrite=True)\r\n    print item.title + \" created\"\r\n\r\ndef replaceAllXMLs():\r\n    msg('Updating All Forms in ArcGIS Online')\r\n    sh = createSecurityHH()\r\n    \r\n    for srv in fsIDs:\r\n        fsID = fsIDs[srv]\r\n        xml = os.path.join(formsFolder, fsID, srv + '.xml')\r\n        print '\\nReplacing: ' + srv\r\n        print ' ~FSID = ' + fsID\r\n        replaceXML(sh, srv, xml, fsID)\r\n\r\nif __name__ == '__main__':\r\n    replaceAllXMLs()"}}
{"actor":{"display_login":"delfavero"}}