I have a survey form that is used to raise permits in a given area which uses a pulldata function and a javascript script to highlight clash detection between the drawn polygon in the survey and any existing polygons from the same feature layer.
My issue is that the script pulls all polygons that have ever been created in that area but I would like to implement a condition into either the pulldata funciton or the javascript where it only pulls "Live" polygons. I have an attribute called comp_status which can be set to "live", "draft" or "closed" by users which I would use to govern this condition/filter but I am unsure how to write it.
pulldata function from Survey123 Connect xlsx:
pulldata("@javascript", "Permit_SelfOverlap.js", "overlapDetection" ,${work_loc}, pulldata("@property","token"),"https://services-eu1.arcgis.com/rZUtSj7wo4TEaL9N/arcgis/rest/services/service_9513f17b339d4464a31aef...", true)
javascript script:
function overlapDetection(geometry, token, featurelayer_url, debugmode) {
// If there is no geometry input, output null
if (!geometry) {
return "Waiting for input geometry.";
}
// If the survey is submitted in the webapp, convert the geometry to object
if (typeof(geometry) != "object") {
var geoArray = geometry.split(';');
geoArray.forEach(ArraytoAA);
var geoObject = {"rings": [geoArray]};
//return (debugmode? "Debug message 1":"");
} else {
var geoObject = geometry;
}
// Convert javaScipt object to a JSON string
var geoString = JSON.stringify(geoObject);
//return geoString;
// Change the parameters in the query URL to work with different geometryType, spatialRel, etc.
var url = featurelayer_url + "/query?";
if (token) {
url = url+"&token="+token;
};
// For returnDistinctValues, If true, it returns distinct values based on the fields specified
// in outFields. This parameter applies only if the supportsAdvancedQueries property of the layer
// is true. This parameter can be used with returnCountOnly to return the count of distinct values of subfields.
// Make sure to set returnGeometry to false when returnDistinctValues is true. Otherwise,
// reliable results will not be returned. &1%3D1 permitstat%3D'Closed'
var params = ("'&geometry="+geoString+"&geometryType=esriGeometryPolygon&spatialRel=esriSpatialRelIntersects&units=esriSRUnit_Meter&returnDistinctValues=true&outFields=permit_no,rasier_name,permit_exp&returnGeometry=false&f=json");
// create a new XMLHttpRequest object to request data from the server. Then define the type of request
// method (GET or POST), the file location (url) and async (true (asynchronous) or false (synchronous))
// send() sends a request to the server (used for GET).
var xhttp = new XMLHttpRequest();
xhttp.open("POST", url, false);
// Send the proper header information along with the request
xhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
xhttp.send(params);
// status 200: OK
if (xhttp.status!==200) {
return (xhttp.status);
} else {
if (xhttp.responseText === undefined) {
return "No overlap found!";
} else {
var responseJSON=JSON.parse(xhttp.responseText);
if (responseJSON.error) {
return xhttp.responseText; //JSON.stringify(responseJSON.error);
} else if (responseJSON.features[0] === undefined) {
return "No live permits overlapped.";
} else {
let overlaps = '';
for (var i = 0; i < responseJSON.features.length; i++) {
// for (var i in responseJSON.features) {
// return JSON.stringify(responseJSON.features);
//responseJSON.forEach(function(element) {
overlaps += "|| " + "<b>Permit Number:</b> " + JSON.stringify(responseJSON.features[i].attributes["permit_no"]) + ", <b>Raised By:</b> " + JSON.stringify(responseJSON.features[i].attributes["rasier_name"]) + ", <b>Permit Expiry Date: </b>" + JSON.stringify(responseJSON.features[i].attributes["permit_exp"]) + "|| " + "\n" ;
}
return overlaps;
}
}
}
}
function ArraytoAA(item,index,array) {
var coord = item.split(' ').map(Number)
array[index] = coord;
}