Hello Survey123 for ArcGIS Team
I'm attempting to use the example given in the Custom pulldata() JavaScript Functions
here. However, I'm struggling with how to request a security token. Here's my setup:
var url = "https://services1.arcgis.com/xxxxxxx/arcgis/rest/services/xxxxxx/FeatureServer/0/query?where="
+"FACILITYID+%3D+%27" + ID +"%27"+"&objectIds=&time=&geometry=&geometryType=esriGeometryEnvelope&inSR=&spatialRel=esriSpatialRelIntersects&resultType=none&distance=0.0&units=esriSRUnit_Meter&returnGeodetic=false&outFields=*&returnHiddenFields=false&returnGeometry=true&multipatchOption=xyFootprint&maxAllowableOffset=&geometryPrecision=&outSR=&datumTransformation=&applyVCSProjection=false&returnIdsOnly=false&returnUniqueIdsOnly=false&returnCountOnly=false&returnExtentOnly=false&returnDistinctValues=false&orderByFields=&groupByFieldsForStatistics=&outStatistics=&having=&resultOffset=&resultRecordCount=&returnZ=false&returnM=false&returnExceededLimitFeatures=true&quantizationParameters=&sqlFormat=none&f=pjson&token=BIG OLD SECURITY TOKEN"
However, now I'm struggling with how to go about adding in a token request to my JS script. So:
"Sometimes, particularly when using JS to access web services and secure ArcGIS services, you may need some properties that are not available through standard XLSForms. For this reason, we have also extended the collection of properties you can obtain through property() function as follows:
property('propertyname')
- portalurl
- token
..."
Any help would be greatly appreciated.
You can make an HTTP request to generate the token:
var xhr = new XMLHttpRequest();
var tokenURL = 'https://www.arcgis.com/sharing/rest/generateToken';
var params = 'f=pjson&username=jskinner_CountySandbox&password=******&referer=http://www.arcgis.com';
xhr.open('POST', tokenURL, true);
xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
xhr.onreadystatechange = function () {
var response = (xhr.responseText);
var obj = JSON.parse(response);
var token = obj['token'];
console.log(token);
};
xhr.send(params);
Thanks Jake Skinner, but with a little help from James Tedrick I figured this out. For anyone who'd like to replicate this I have attached my full survey, including the 'extension' folder containing the JS Script. Here's how to get it running:
Hi Jake,
Can I ask how where code would be implemented within the queryPolygon function seen on this esri blog post under "Working with web services"?
This is AWESOME! Just got a project doing something similar to this I think that was going to use an external csv, but might just use a REST service since the script is pretty much already built.
I have a few questions after reading through this thread that I would like clarified:
1) Reading through the documentation though, I can't tell if it is still in beta or if it made it to the production application.
2) Is this functionality able to be used solely within Survey123 or is Workforce required? Looking to have a list of project numbers in a REST service that populate a dropdown within Survey123.
Thanks!
I can answer #2 - it can be used with any rest service. You just need a mechanism to feed a value into a field in your survey, which the JS script takes to query "the other" feature service. In my case I passed Workforces' location into FacilityID. I then took the value of FacilityID (now populated) and used that in my JS query to "the other" feature service.
I can't answer #1 - I'd ask James Tedrick
Are you using it in a beta version of Survey123 or production version?
Huh, you brought up a good use case that I never thought of!
Did you try creating a geopoint inside Survey123 and using that instead of your workflow of using Workforce to get the location? Which leads to my second question, do you have to pass it as a parameter IN to your survey so it runs on the loading of the survey, or is it able to be executed/ran once the survey is loaded?
I'm using #survey 123 connect v3.1.113
For your first point - I create my own GeoPoint in Survey. The purpose of my workflow is to audit check the point collected in "the other" feature service. So I compare the location of the two points back in the office.
As for the second question - yes, it needs whatever value you intend to query your "other" feature service with passed in a parameter when opening the form. The JS script fires upon opening .
Hi David,
Beween the posting of the document and now, the property() function ws deprecated from the XLSForm specification; in it's place, you can use the pulldata('@property', 'token') calculation to retrieve the logged in user's token, and then pass that as a parameter.
James Tedrick Is the JS functionality through the pulldata function available for all users on the Survey123 clients? We get "Extension disabled" errors when we try to perform this in Survey123... Is there a special beta or early adopter that we need to use to overcome this?