Select to view content in your preferred language

Survey123 Pulldata con Servicio Web

864
1
Jump to solution
05-03-2019 12:08 PM
DannielaCardenas
Occasional Contributor

Buenas tardes 

Quisiera preguntar si es posible hacer Pulldata para una encuesta de Survey123 y este llame información de un Servicio Web. Muchas gracias!! 

1 Solution

Accepted Solutions
josevaldes1
Regular Contributor

verifica si esto te ayuda. yo lo estoy usando.

Starting at version 3.0, we would like to enable you to extend the pulldata() function with your own JavaScript functions.  This is an advanced technique that can help you introduce logic beyond what is possible through standard XLSForm syntax.

The pulldata() function is designed to help you return a single value. Just as a reminder, pulldata() is typically used to:

  • Perform lookups against a CSV table
  • Get certain properties from geopoint objects
  • Get properties from a JSON object
  • Get EXIF metadata

Our proposal is to now also let you invoke your own JavaScript functions to return values: You decide what goes on within your JavaScript function!

The syntax for using your own JS functions with pulldata is as follows:

pulldata("@javascript","yourJSFile.js","yourFunction","parameter1","parameter2")

Your custom JavaScript files must be stored in a folder called 'extensions' within the survey directory.  You can add as many function parameters as needed. In the example above, the JS function is expecting 2 parameters, but you could more or less as needed by your own function

To help you get started, I have created a survey that will show the basics. Just a few words of wisdom:

  • You cannot use DOM
  • You cannot use frameworks such as JQuery, Ember, Angular etc
  • You cannot access local files
  • You cannot make asynchronous calls

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
  • online - Boolean value indicating if device has network connectivity
  • utcoffset - Offset in minutes from UTC for the local timezone - Note: This can also be done in JavaScript via var utcOffset = - new Date().getTimezoneOffset
  • language - Language in use by current survey
  • locale - Locale object in use for current survey. Only useful for JavaScript functions
  • localeinfo - AppStudio LocaleInfo object for current survey - Only useful for JavaScript functions. LocaleInfo contains the language code in various notations
  • timezone - Timezone code

It is time for you to have fun! Please use the forums to let us know how things go. Write your notes no matter if things go well or not.

ejemplo dan de esri:

function returnFirstIntersectingFeature(featureLayer,location,fields,token,debugmode){
    if (location===""){
        return (debugmode? "Location object is empty":"");
    }
    var coordsArray = location.split(" ");
    var coords = coordsArray[1] + "," + coordsArray[0]
    var xmlhttp = new XMLHttpRequest();
    var url = featureLayer + "/query?geometry=" + coords + "&geometryType=esriGeometryPoint&inSR=4326&spatialRel=esriSpatialRelIntersects&outFields=" + fields + "&returnGeometry=false&returnCount=1&f=pjson"
    if (token){
        url = url + "&token=" + token;
    }

    xmlhttp.open("GET",url,false);
        xmlhttp.send();

    if (xmlhttp.status!==200){
        return (debugmode? xmlhttp.status:"");
    } else {
        var responseJSON=JSON.parse(xmlhttp.responseText)
        if (responseJSON.error){
            return (debugmode? JSON.stringify(responseJSON.error):"");
        } else {
            if (responseJSON.features[0]){
                return JSON.stringify(responseJSON.features[0]);
            }
            else{
                return (debugmode? "No Features Found":"");
            }
        }
    }
}

View solution in original post

0 Kudos
1 Reply
josevaldes1
Regular Contributor

verifica si esto te ayuda. yo lo estoy usando.

Starting at version 3.0, we would like to enable you to extend the pulldata() function with your own JavaScript functions.  This is an advanced technique that can help you introduce logic beyond what is possible through standard XLSForm syntax.

The pulldata() function is designed to help you return a single value. Just as a reminder, pulldata() is typically used to:

  • Perform lookups against a CSV table
  • Get certain properties from geopoint objects
  • Get properties from a JSON object
  • Get EXIF metadata

Our proposal is to now also let you invoke your own JavaScript functions to return values: You decide what goes on within your JavaScript function!

The syntax for using your own JS functions with pulldata is as follows:

pulldata("@javascript","yourJSFile.js","yourFunction","parameter1","parameter2")

Your custom JavaScript files must be stored in a folder called 'extensions' within the survey directory.  You can add as many function parameters as needed. In the example above, the JS function is expecting 2 parameters, but you could more or less as needed by your own function

To help you get started, I have created a survey that will show the basics. Just a few words of wisdom:

  • You cannot use DOM
  • You cannot use frameworks such as JQuery, Ember, Angular etc
  • You cannot access local files
  • You cannot make asynchronous calls

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
  • online - Boolean value indicating if device has network connectivity
  • utcoffset - Offset in minutes from UTC for the local timezone - Note: This can also be done in JavaScript via var utcOffset = - new Date().getTimezoneOffset
  • language - Language in use by current survey
  • locale - Locale object in use for current survey. Only useful for JavaScript functions
  • localeinfo - AppStudio LocaleInfo object for current survey - Only useful for JavaScript functions. LocaleInfo contains the language code in various notations
  • timezone - Timezone code

It is time for you to have fun! Please use the forums to let us know how things go. Write your notes no matter if things go well or not.

ejemplo dan de esri:

function returnFirstIntersectingFeature(featureLayer,location,fields,token,debugmode){
    if (location===""){
        return (debugmode? "Location object is empty":"");
    }
    var coordsArray = location.split(" ");
    var coords = coordsArray[1] + "," + coordsArray[0]
    var xmlhttp = new XMLHttpRequest();
    var url = featureLayer + "/query?geometry=" + coords + "&geometryType=esriGeometryPoint&inSR=4326&spatialRel=esriSpatialRelIntersects&outFields=" + fields + "&returnGeometry=false&returnCount=1&f=pjson"
    if (token){
        url = url + "&token=" + token;
    }

    xmlhttp.open("GET",url,false);
        xmlhttp.send();

    if (xmlhttp.status!==200){
        return (debugmode? xmlhttp.status:"");
    } else {
        var responseJSON=JSON.parse(xmlhttp.responseText)
        if (responseJSON.error){
            return (debugmode? JSON.stringify(responseJSON.error):"");
        } else {
            if (responseJSON.features[0]){
                return JSON.stringify(responseJSON.features[0]);
            }
            else{
                return (debugmode? "No Features Found":"");
            }
        }
    }
}
0 Kudos