Is it possible to send data back from Survey123 in a callback URL?

1742
13
05-26-2021 01:28 PM
DougBrowning
MVP Esteemed Contributor

After hours of trying I think I know the answer but I wanted to check.

I finally got a callback URL (that double encoding is lots of fun) to work once I switched to hardcoding the values.  There are no help samples of this.

Here is my sample hardcodeing the callback values and feature globalid

arcgis-survey123://?itemID=9269d29cfc994accb9c3739c556ee345&field:LOCAL_ID={LOCAL_ID}&field:GeoGUID={globalid}&callback=https%3A%2F%2Ffieldmaps.arcgis.app%3FitemID%3D60898699d9194370985ba5d1b88ac966%26referenceContext%3DupdateFeature%26featureSourceURL%3Dhttps%3A%2F%2Fservices1.arcgis.com%2FHp6G80Pky0om7QvQ%2Farcgis%2Frest%2Fservices%2FPFCRCTest4%2FFeatureServer%2F0%26featureID%3D431c51d1-2570-4677-a13e-4a42d582cf66%26featureAttributes%3D%257B%2522LOCAL_ID%2522%3A%2522testhardcode%2522%2C%2522FormGUID%2522%3A%2522hardid%2522%257D

But what I would like to do is pull a field back from 123.  I am doing this to link the forms in both directions.  I want to send back a guid that I generate in 122.

I have tried this (unencoded).  Just the callback part works from 123 so I got that part right and I can use 123 fields just fine.

arcgis-survey123://?itemID=9269d29cfc994accb9c3739c556ee345&field:LOCAL_ID={LOCAL_ID}&field:GeoGUID={globalid}&callback=https://fieldmaps.arcgis.app?itemID=60898699d9194370985ba5d1b88ac966&referenceContext=updateFeature&...${LOCAL_ID}%22,%22FormGUID%22:%22${FormGUID}%22%7D

I have a feeling that the callback URL is hard generated at the time of the call in Field Maps.  That means referencing a field in 123 with ${LOCAL_ID} makes no sense since you are in Field Maps at the time the URL is generated.  Am I right?

If I am in right is there any way to send data to 123 via a URL then use callback to send 123 data back in to Field Maps?

thanks for any help

13 Replies
DougBrowning
MVP Esteemed Contributor

Not seeing this covered still looking thanks  

https://doc.arcgis.com/en/survey123/reference/integratewithotherapps.htm 

0 Kudos
AnthonyJonesRSK
Occasional Contributor II

Hi Doug,

I stumbled across your post after looking into the use of url callbacks. I agree the ability to send data back from Survey123 would be great. After reading your post and a lot of tinkering with the encoding I at least managed to set up a system where once the survey has been completed the callback goes back to the polygon layer and updates a status field to indicate that the associated survey has been completed for that particular polygon. My hope is that this will help our surveyors keep track of which features they've fully completed. Plus with the new filter options in Field Maps it means they can filter to show those they've missed.

So I'm not really offering anything new to the conversation but just wanted to say thanks as your post convinced me that more complex call backs are possible! Cheers  

DougBrowning
MVP Esteemed Contributor

Cool can you post a sample?  My guess is you could hardcode the data somehow.  

0 Kudos
AnthonyJonesRSK
Occasional Contributor II

Sure. My url is generated in Arcade, see below. You can ignore most of it but I spent a long time trying to get the callback variables to work. Basically I found that if I included my callback variables in a parameters dictionary as I've done for the survey123 parameters and then used the UrlEncode function, Field Maps didn't appear to like that and kept telling me that I needed to supply the featureID parameter despite it being there in the url. I ended up realising that Field Maps doesn't like any ampersands after the callback which is why I've had to encode these manually rather than using the UrlEncode function on the parameters dictionary, which kept adding the ampersands back in. 

The callback part of my script could probably be written a bit more elegantly as I'm still fairly new to Arcade but this worked so I didn't want to mess with it too much! Like you say it would be great to pull data back from S123 in the callback but I was at least glad to be able to get it to update the layer in Field Maps once the form had been completed. The only thing I don't like is that when it goes back to Field Maps the updateFeature element reopens the form and it'd be great if it just wrote "Yes" to the field without the form being opened again, to avoid the surveyor changing anything else by accident. 

Don't know if that's of any of use but just wanted to acknowledge your post as it was the first thing I'd seen that suggested additional callback parameters may be possible. Cheers

//Convert coordinates to wgs84 for use in survey123
function WebMercatorToWGS84 (x, y) {
    var lon = (x / 20037508.34) * 180;
    var lat = (y / 20037508.34) * 180;
    lat = 180/PI * (2 * Atan(Exp(lat * PI / 180)) - PI / 2);

    return {
        y: lat,
        x: lon
    }
}
//Launch survey123
var urlsource ="arcgis-survey123://?itemid=XXXXXXX&";
//Get centroid of feature
var geom = Centroid($feature)
//Generate coordinates from centroid
var coords =  WebMercatorToWGS84(geom.x, geom.y)
//Format coordinates so they work with survey123 geopoint
var splitcoords = coords.y + "," + coords.x
//Get polygon area to pass to survey123
var featurearea = Round(AreaGeodetic($feature, 'square-meters'), 2)
//Format globalid
var fglobalid = Mid($feature.globalid, 1,36)
//Generate other url parameters to pass to survey123
var params = {
  center: splitcoords,
  "field:FeatureProjectCode": $feature.PolygonProjectCode,
  "field:FeatureSiteID": $feature.PolygonSiteID,
  "field:IDCount": $feature.PolygonCount,
  "field:CommonName": $feature.PolygonCommonName,
  "field:parentglobalid": $feature.parentglobalid,
  "field:GeometryGUID": $feature.globalid,
  "field:FeatureType": "Polygon",  
  "field:FeatureSize": featurearea
};
var callback = {
}
var callbackid = "featureID=" + fglobalid
var callbackattributes = 'featureAttributes={"PolygonDataEntered":"Yes"}'

return urlsource + UrlEncode(params) + "&" + UrlEncode(callback) + "%26" + UrlEncode(callbackid) + "%26" + UrlEncode(callbackattributes)
utenalarosa
New Contributor III

Would your process work if I have a public S123 that goes into webmap which lunches internal S123 for inspection. Any help in how to set this up and be able to pass parameter between the collected information in the first survey and the second survey.

Thanks 

0 Kudos
DougBrowning
MVP Esteemed Contributor

Yes you can use a URL to launch a form the same way as you do in field maps, no different.  Just make a note field and have the link in the label part.

0 Kudos
utenalarosa
New Contributor III

So i am able to lunch the second s123 with the correct globalid in the url what i don't know how to do is store that information on a field called ParentID.

0 Kudos
GuyWeerasingheAFF
New Contributor III

Amazing - this has been good to dabble with - my issue is that I can't get the last section for call back attributes changing

//Launch survey123
var urlsource ="arcgis-survey123://?itemid=XXXXXX&";

//Generate other url parameters to pass to survey123
var params = {
"field:SubmittingGlobalID": $feature.GlobalID,
"field:NAQSActivityCodeTemp": $feature.ReviewedSurveyID,
"field:Starting_survey_ID": $feature.First_specimen,
"field:AnimalType": $feature.SurveyType,
"field:SpeciesUnderInvestigation": $feature.CommonName,
"field:Feral_Group_ID": $feature.Group_ID,
};
var callback = {
callback: "https://fieldmaps.arcgis.app/?referenceContext=updateFeature&itemID=XXXXXXXX&featureSourceURL=XXXXXX...",
}
var callbackid = "featureID=" + GlobalID
var callbackattributes = 'featureAttributes={"SampledGroup":"Yes"}'

return urlsource + UrlEncode(params) + "&" + UrlEncode(callback) + "%26" + UrlEncode(callbackid) + "%26" + UrlEncode(callbackattributes)

 

When I use this approach, I can go to survey123, plug my data in and then return back to the app, but the callback attributes just doesn't work, just lands on field maps with the old pop up. Seeking even a suggestion that opens up the form at attribute that needs to be filled in

0 Kudos
AndrewPadilla
Occasional Contributor

@DougBrowning , @AnthonyJones5 Is there any news on the ability to callback a Survey123 field into Field Maps?  I have been able to hard code as noted above but would like to be able to use the callback feature and write a survey123 field back into Field Maps. Ideal Workflow: Open Field Maps popup, button opens survey123, writes two attributes to survey123, when survey is submitted callback opens Field Maps centers on feature, and writes two survey123 attributes. It's just the last bit I can't seem to get to work.

Using the above example it would look something like this: 

var callbackattributes = 'featureAttributes={"PolygonDataEntered":"$feature.Survey123attribute"}'

Thanks!

0 Kudos