Help with Survey123 link from Field Maps with callback to Field Maps

2494
16
Jump to solution
07-07-2023 09:54 AM
DavidHood_USFS
New Contributor III

I'm trying to create a link to launch a survey123 survey with attributes passed from the selected feature in field maps and then use the callback to return to field maps and update an attribute on the feature that the survey was launched from.  I've been reading ESRI's documentation at https://doc.arcgis.com/en/survey123/reference/integratewithotherapps.htm and https://doc.arcgis.com/en/field-maps/ios/help/deploy-your-map.htm along with posts here in the community but can't get the attributes to update with the callback and not sure what I'm missing.  I'm using the Arcade content within the popup to add the link and I've attached my Arcade code below.  It launches Survey123 and populates attributes in the Survey as I want and returns to field maps when the survey is submitted, but I can't get the attribute to update on the callback.

featureSourceURL is the url to the hosted feature service and the layer within that service is layer 0.  I'm thinking this might be part of the problem as if I past the url into the browser I get a token required page, but I've tried generating a token and adding the token to the url and that broke the callback.

 

var S123 = "arcgis-survey123://?itemID=###"
var S123_Attributes = "&field:Stand_Habitat_Type={Stand_Habitat_Type}&field:incoming={GlobalID}"

var Callback = "&callback="
var CallbackFM = UrlEncode("https://fieldmaps.arcgis.app/?referenceContext=updateFeature")
var callbackID = UrlEncode("&itemID=###")
var callbackFeatureSource = UrlEncode("&featureSourceURL=https://services1.arcgis.com/###/arcgis/rest/services/AspenSurvey/FeatureServer/0")
var callbackFeatureID = UrlEncode("&featureID=")
var callbackFeatureGlobalID = UrlEncode($feature.GlobalID)
var callbackFeatureAttributes = UrlEncode('featureAttributes={"ConditionSurvey":"Yes"}')
var fullCallback = CallbackFM + callbackID + callbackFeatureSource + callbackFeatureID + callbackFeatureGlobalID + callbackFeatureAttributes
var fullURL = S123 + S123_Attributes + Callback + fullCallback

return { 
	type : 'text', 
	text : '<a href=' + fullURL + '>Open Survey with Callback</a>' 
}

 

1 Solution

Accepted Solutions
DavidHood_USFS
New Contributor III

Thanks again for the help Doug. I was able to get this working with some help from another coworker and wanted to share what I did in case anyone else has similar issues.

Confirgure popups for the layer and go to Options > Attribute Expressions.  I created a new expression with the code below.  I then used the Add Content and added a text element to the popup and used the field for that expression to create the link.  This didn't really change anything from what I had originally so not sure what exactly the problem was, but glad I got it working.

// To launch survey123 from map
// EDIT THIS LINK TO MATCH YOUR SURVEY LINK (Only edit AFTER itemID= and BEFORE &

var urlsource ="arcgis-survey123://?itemID=###&"
 
//Format globalid to "link" survey point to map data  -- MUST have globalid field for this script to work. DO NOT EDIT THIS LINE

var fglobalid = Mid($feature.GlobalID, 1,36)

//Generate other url parameters to pass to survey123. -- These are the values you wish to transfer from Field Maps to your Survey123 form.
// Edit or delete fields as necessary. The line containing $feature.GlobalID MUST NOT BE REMOVED, but the field to the left of $feature.GlobalID may
// be changed to reflect the field in your Survey to store the GlobalID.

var params = {
  "field:incoming": $feature.GlobalID,
  "field:Stand_Habitat_Type": $feature.Stand_Habitat_Type,  
};


// Create callback portion of link using itemID (map ID) and featureSourceURL (services link to the layer containing the feature to be edited following survey submission)
// EDIT THIS LINK FOR LNF MAP AND LNF POINT FEATURE CLASS.  updateFeature&itemID=<your maps ID>&featureSourceURL=<link to the feature class to be edited>

var callback = {
  callback:"https://fieldmaps.arcgis.app/?referenceContext=updateFeature&itemID=###&featureSourceURL=https://services1.arcgis.com/###/arcgis/rest/services/AspenSurvey/FeatureServer/0",

}

// // Add featureID (must be var fglobalid) portion of callback link
// THIS LINE MUST NOT BE CHANGED. This line is what tells the script which point in the feature class will be edited

var callbackid = "featureID=" + fglobalid


var callbackattribute = 'featureAttributes={"ConditionSurvey":"Complete"}'  // -- this would edit the ConditionSurvey field to reflect survey at the current point is complete


// Return the entire link/URL. This is what the FieldMaps app is following when you click the link to enter survey data. This should not be changed unless there is no callback
// attribute to pass back to Field Maps

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


// For use in the pop-up for your featureclass, simply enter the expression name in the link field (i.e. {expression/expr0})

 

View solution in original post

16 Replies
DougBrowning
MVP Esteemed Contributor

These can be really hard. 

The issue I had was the URL is static when made and cannot send back any new data which makes sense but you seem to have static data.  I think I got away with no encoding but I do not remember.  

This post may help you  https://community.esri.com/t5/arcgis-field-maps-questions/is-it-possible-to-send-data-back-from-surv...

Good luck

 

0 Kudos
DavidHood_USFS
New Contributor III

Thanks Doug, I have read that previous post of your and the replies several times and was where I got some of my arcade script from.  Yeah, I'm pulling attributes from data in the map and the link has those replaced properly when I check in within map viewer.

Though I just went to double check the link that is being created in Map Viewer and the FeatureID is properly populating with the features GlobalID, I did noticed the featureAttribute part is still showing up with the " in the URL (featureAttributes%3D%7B"ConditionSurvey"%3A"Yes"%7D) using the Arcade UrlEncode function so I tried manually encoding it then encoding it again and I'm able to rid of them but still not updating the feature as it appears should happen (featureAttributes%253D%257B%2522ConditionSurvey%2522%253A%2522Yes%2522%257D).

Here is the full URL (double encoded on the featureAttribute part) I'm getting, though I've redacted ItemID's with ## as well as part of the Feature URL:  arcgis-survey123://?itemID=##&field:Stand_Habitat_Type=Talus&field:incoming=82cf6bd4-a4d6-43d7-a955-9ed42e2f1ea4&callback=https%3A%2F%2Ffieldmaps.arcgis.app%2F%3FreferenceContext%3DupdateFeature%26itemID%3D##%26featureSourceURL%3Dhttps%3A%2F%2Fservices1.arcgis.com%2F##%2Farcgis%2Frest%2Fservices%2FAspenSurvey%2FFeatureServer%2F0%26featureID%3D82cf6bd4-a4d6-43d7-a955-9ed42e2f1ea4featureAttributes%3D%7B%22ConditionSurvey%22%3A%22Yes%22%7D

0 Kudos
DougBrowning
MVP Esteemed Contributor

If I remember right I never got using fields to work in the callback but hardcoding like you did I think I did get one of these two to work.  Trying to remember but I think when I did it I made the whole URL then encoded it on a website encoder then pasted that in the popup.

Maybe it will give you a hint.  Sorry I do not know more.

arcgis-survey123://?itemID=9269d29cfc56ee345&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


arcgis-survey123://?itemID=92656ee345&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

Only thing I see is you have referenceContext then the itemid and I have itemid then referenceContext.  I remember playing with that but not sure if that is it.

0 Kudos
DavidHood_USFS
New Contributor III

Thanks again for the help Doug. I was able to get this working with some help from another coworker and wanted to share what I did in case anyone else has similar issues.

Confirgure popups for the layer and go to Options > Attribute Expressions.  I created a new expression with the code below.  I then used the Add Content and added a text element to the popup and used the field for that expression to create the link.  This didn't really change anything from what I had originally so not sure what exactly the problem was, but glad I got it working.

// To launch survey123 from map
// EDIT THIS LINK TO MATCH YOUR SURVEY LINK (Only edit AFTER itemID= and BEFORE &

var urlsource ="arcgis-survey123://?itemID=###&"
 
//Format globalid to "link" survey point to map data  -- MUST have globalid field for this script to work. DO NOT EDIT THIS LINE

var fglobalid = Mid($feature.GlobalID, 1,36)

//Generate other url parameters to pass to survey123. -- These are the values you wish to transfer from Field Maps to your Survey123 form.
// Edit or delete fields as necessary. The line containing $feature.GlobalID MUST NOT BE REMOVED, but the field to the left of $feature.GlobalID may
// be changed to reflect the field in your Survey to store the GlobalID.

var params = {
  "field:incoming": $feature.GlobalID,
  "field:Stand_Habitat_Type": $feature.Stand_Habitat_Type,  
};


// Create callback portion of link using itemID (map ID) and featureSourceURL (services link to the layer containing the feature to be edited following survey submission)
// EDIT THIS LINK FOR LNF MAP AND LNF POINT FEATURE CLASS.  updateFeature&itemID=<your maps ID>&featureSourceURL=<link to the feature class to be edited>

var callback = {
  callback:"https://fieldmaps.arcgis.app/?referenceContext=updateFeature&itemID=###&featureSourceURL=https://services1.arcgis.com/###/arcgis/rest/services/AspenSurvey/FeatureServer/0",

}

// // Add featureID (must be var fglobalid) portion of callback link
// THIS LINE MUST NOT BE CHANGED. This line is what tells the script which point in the feature class will be edited

var callbackid = "featureID=" + fglobalid


var callbackattribute = 'featureAttributes={"ConditionSurvey":"Complete"}'  // -- this would edit the ConditionSurvey field to reflect survey at the current point is complete


// Return the entire link/URL. This is what the FieldMaps app is following when you click the link to enter survey data. This should not be changed unless there is no callback
// attribute to pass back to Field Maps

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


// For use in the pop-up for your featureclass, simply enter the expression name in the link field (i.e. {expression/expr0})

 

AndrewPadilla
Occasional Contributor

@DavidHood_USFS  Thanks for your detailed commenting in the example you provided. I was struggling with a callback until I found this post. Cheer!!

0 Kudos
AnastasiiaBlöchl
New Contributor

Dear David,
does this also work offline? I would like to create a FieldMaps with Survey link in pop ups for an inspection. When the survey is filled out, I should "jump" back to the field maps. The problem is after the completed survey the point in Field Maps should change from red (inspection was not completed) to green (inspection was completed). But all this should run offline. Is it possible? I would like to know the answer first before I start creating the whole web map, field maps project and surveys.

Thank you in advance!

0 Kudos
DavidHood_USFS
New Contributor III

Yes this worked offline in my testing.

AnastasiiaBlöchl
New Contributor

Thank you!

 

0 Kudos
Marcel_Schmidt
New Contributor

During my testing it didn't work.

When Survey123 and FieldMaps App are offline (for example during a tree inventory in a forest) i think it is not possible, that the data can be pased from one app to the other app because the step of syncronisation with arcgis online is needed. The two apps have different folders on the mobile device, where the data is stored local for offline use, so there is no connection possible when both apps are offline.

 

How did you manage to make it work offline?  Thank you in advance!

0 Kudos