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>'
}
Solved! Go to Solution.
I have modified your code as follows:
// To launch survey123 from map
// EDIT THIS LINK TO MATCH YOUR SURVEY LINK (Only edit AFTER itemID= and BEFORE &
var urlsource ="arcgis-survey123://?itemID=67e58096e6c34a89a40a98176f0b3e61&action=edit&"
//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 = {
"q:globalId": $feature.GlobalID,
"field:Baumart": $feature.Baumart,
"field:Bemerkung": $feature.Bemerkung,
"field:latitude": Geometry($feature).Y,
"field:longitude": Geometry($feature).X,
};
// 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=open&itemID=08fdeaa4afdb4c75a82e417e98a0f4f1&featureSourceURL=https://services1.arcgis.com/ZGLt3tM6U3J8q1rO/arcgis/rest/services/Inventurpunkte/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) + "&" + "update=true&" + 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})
I've just been working to implement this code in my URL using the full callback and feature update (edit) capabilities (previously was just calling the app and stopping there). I think I found a bug in the fglobalid variable assignment (Line 8). You're using:
var fglobalid = Mid($feature.GlobalID, 1,36)
but this seems to be trimming off the first character of the GlobalID value (index should start at 0 instead of 1?).
I tidied it up though to simply be:
var fglobalid = $feature.GlobalID
Curious to know why you didn't do this in the first case.
Cheers!
Thank you for the Reply,
when I use this line:
var fglobalid = $feature.GlobalID
I get the globalID with the curly brackets as output, for expamle: {r892e0hj-2h98h23h-8934610n-q32n1751}.
For this reason I have to trimm of the first and last charakter of the globalID to get the number without the curly brackets.
Best regards
Marcel Schmidt
Ok - thats interesting. I haven't seen any evidence of the curly brackets in my URL's when running my validation in the Arcade editors and copying the URL's in the browser.....BUT!......I've just reimplemented the original MID code and testing in Field Maps and it works! Turns out the app returns {a1b2c3-d4e5...} whereas in my web browser I was only seeing a1b2c3-d4e5... which when combined with the MID code would drop the first character (leaving me with 1b2c3-d4e5...).
Lesson learnt - trust the code authors! At least I hope others can learn from my trials and tribulations documented here!
For those looking at the above solutions, here's my cutback version of the code provided which still passes attributes from the selected feature to the survey and does the callback, but without the portion of the code that updates the feature in FieldMaps after completing the survey (simply put, launches a survey but returns you to FieldMaps with the original feature selected but no edits occur).
Thanks @DavidHood_USFS for this code - it works a treat!
// 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.
var params = {
"field:plantation": $feature.Field1,
"field:compartment": $feature.Field2,
"field:stand": $feature.Field3,
};
// Create callback portion of link using itemID (map ID)
// Only edit AFTER itemID=
var callback = {
callback:"https://fieldmaps.arcgis.app/?referenceContext=open&itemID=################################",
}
// // 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 selected
var callbackid = "featureID=" + fglobalid
// 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)
return urlsource + UrlEncode(params) + "&" + UrlEncode(callback)
// For use in the pop-up for your featureclass, simply enter the expression name in the link field (i.e. {expression/expr0})
One note - if you want to simply flip back to Field Maps all you have to do is this &callback=https://fieldmaps.arcgis.app and it will quickly flip back to the app. No need to specify a item or anything else. It just returns to whatever state it was and is fast.
For me I skip Arcade totally to build the URL and simply use a custom popup with HTML. I use Arcade to grab any data I want from a parent but other than that you can just reference the field you want then ref the the URL using {expression/expr13}. Also no need to Encode the URL. It works fine.
arcgis-survey123://?itemID=a44a3e1513ecf36567&field:PointID={PointID}&field:EvaluationID={expression/expr0}&field:CollectTNTP={expression/expr13}&field:CollectTurbidity={expression/expr14}&field:Project={Project}&field:ProtocolType={ProtocolType}&field:StreamName={expression/expr35}&callback=https://fieldmaps.arcgis.app
I am sure there may be times when you need Arcade for the URL but for most cases I just build them out in a text doc and then add the URL in the pop up. Been working for years now.
Hope that helps someone.
Thanks for the additional tips. I have no HTML knowledge so the seemingly more convoluted Arcade method works for me (eventually). Learning as I go though so may try the HTML option soon! Will amend the callback based on your suggestion.
Hi Doug. I've just been playing around with the HTML code you posted and I have 2 queries.
1. Does this need the GlobalID info referenced somewhere as per the Arcade version to link the features?
2. Do you know how to format it to appear nicely in the popup
For Example;
My URL
instead of;
arcgis-survey123://?itemID=a587781fd350430cadec4&field:plantation=Grimwade&field:compartment=2&field:stand=65&field:year_planted=1995&field:species=P.RAD&field:tenure=State Forest / Timber Reserve&field:AR_Cat=State&callback=https://fieldmaps.arcgis.app
You use the custom popup and then the URL button like this. This is Map Viewer Classic but same concept in new map viewer.
I only create new features not edit. To edit yes you would need the globalid also. I think you can add this by using Arcade to just get the globlalid and add that to the URL using {expression/expr0} notation.
I do that a lot since I need to call from the child to the parent to get a number of fields I need that I then send to the form.
arcgis-survey123://?itemID=38e3353292dsfsdfsdfcb121a6&field:PointID={PointID}&field:EvaluationID={expression/expr0}&field:DesignLat={expression/expr6}&callback=https://fieldmaps.arcgis.app
The Arcade I use for the lookup to the parent is this below.
DesignLat {expression/expr6}
var tbl = FeatureSetByRelationshipName($feature, "Points", ['DesignLat'], false);
return First(tbl).DesignLat
But I think for you if you are in the linking feature just
return $feature.GlobalID should work.
Hope that helps
Thanks for the info - I see you're still using MapViewer Classic. Will have to compare that to the MapViewer and see if it's the same. I've just figured out that the URL function in the popup text editor in MapViewer is setupt a bit differently in that it doesn't have 2 boxes (1 for text and 1 for the URL). Just type the text, highlight, click the URL button then enter the URL. It's the simple things that catch us out sometimes!