Pass attribute field as URL parameter

2753
12
Jump to solution
02-15-2022 08:45 AM
PaulPetersen1
Occasional Contributor

I am attempting to launch Field Maps from Survey123 via URL parameter and pass attributes from Survey123 into a specified feature in Field Maps using the using the Field Maps referenceContext=updateFeature method.

The problem is that I can't figure out how to pass a specified attribute from Survey123 as a URL parameter. This is easy to do going from Field Maps to Survey123, but not so much going the opposite direction.

Basically I've got an guid attribute called Pole_Key in Survey123 that matches the GlobalID of a point feature in the Field Map. I want to use that Pole_Key to open and edit the corresponding record in Field Maps. How do I pass the Pole_Key attribute as a URL parameter from Survey123?

Tags (3)
0 Kudos
1 Solution

Accepted Solutions
PaulPetersen1
Occasional Contributor

@DougBrowning , this is now solved thanks to Esri Tech Support. I am now able to launch Survey123 from the parent point in FieldMaps, perform the survey on a related child record, and then use the callback to pass an attribute back into the original parent record in Field Maps, thus changing the symbol. Whew.

The tricks were:

  • Configure the URL as an Arcade expression, rather than manually
  • Use the URLEncode() arcade function where relevant, although there is a bug (BUG-000146960) associated with this function that limits its current use
  • Use the arcade expression Mid($feature.globalid,1,36)  to strip out the brackets on the GlobalID value within the featureID parameter of the callback.

So my final arcade expression looked something like shown below. It passes in a hard-coded value of "2" to the "RetrofitStatus" attribute field, which was what controls my layer symbology.

var S123urlsource = 'arcgis-survey123://?itemID=xxxxxx&field:Pole_Key='+$feature.globalid+'&callback:submit=';
var FMurlsource='https://fieldmaps.arcgis.app?';
var FMparams='itemID%3Dxxxxxx%26referenceContext%3DupdateFeature%26featureSourceURL%3Dhttps://services1.arcgis.com/xxxx/arcgis/rest/services/xxxx/FeatureServer/0%26';
var FMGID=Mid($feature.globalid,1,36);
var FMAtt='%26featureAttributes%3D%7B%22RetrofitStatus%22%3A%222%22%7D%0A';
return Concatenate(S123urlsource,UrlEncode(FMurlsource),FMparams,'featureID%3D',FMGID,FMAtt);

View solution in original post

12 Replies
DougBrowning
MVP Esteemed Contributor

When you go to Field Maps you have to encode the URL.  But do not have to in 123 - no idea why.

This worked for me note this is for new feature you would need to edit this.

a href="https://fieldmaps.arcgis.app?itemID=bd19b66b22dc21a&referenceContext=addFeature&featureSourceURL=https://services1.arcgis.com/Hp6G80Pky0om7QvQ/arcgis/rest/services/PFC2022TrainingService/FeatureServer/2&featureAttributes=%7B%22LOCAL_ID%22:%22${LOCAL_ID}%22,%22AdminState%22:%22${ADMIN_ST}%22,%22FormID%22:%22${FormID}%22%7D&callback=https://survey123.arcgis.app 

This is a good help page  https://doc.arcgis.com/en/field-maps/android/help/deploy-your-map.htm

Hope that does it

0 Kudos
PaulPetersen1
Occasional Contributor

Hi Doug,

Thanks for the reply! Still not quite working for me. To be more specific, I am trying to pass a Survey123 attribute to Field Maps through a callback. So my basic workflow is:

  1. In Field Maps, user clicks on a point (parent feature class)
  2. In the Field Maps popup, the user then clicks a configured link to open a Survey123 form for a child inspection record (passes parent GlobalID into child Pole_Key)
  3. This same link also includes a callback, so that when the user Submits the Survey123 form, the callback will open the parent form in Field Maps and pass a couple of attributes. The point symbol will then update in Field Maps, showing that the inspection is done.

Right now my link looks something like this. (note that I've edited the exact item IDs, and also note that I haven't encoded the featureID=${Pole_Key} simply for the sake of readability.

 

 

arcgis-survey123://?itemID=xxxxxxxxxxxxxxxxxxxxxxx&field:Pole_Key={GlobalID}&field:PoleNumber={PoleNumber}&field:PoleID={PoleID}&callback:submit=https%3A%2F%2Ffieldmaps.arcgis.app%2F%3FitemID%3Dxxxxxxxxxxxxxxxxxxxxxxx%26referenceContext%3DupdateFeature%26featureSourceURL%3Dhttps%3A%2F%2Fservices1.arcgis.com%2FdscgdziA6jUxpQJw%2Farcgis%2Frest%2Fservices%2Fxxxxxxxxxxxxxxxx%2FFeatureServer%2F0%26featureID=${Pole_Key}%26featureAttributes%3D%7B%22RetrofitStatus%22%3A%222%22%2C%22NumPhotos%22%3A%222%22%2C%22RetrofitProject%22%3A%22test%22%7D%0A

 

 

So I guess my real question is whether I can pass a Survey123 attribute within a callback, and if so, what sort of encoding to I need. I should note that this link works brilliantly when I hard-code the featureID within the URL (for testing), but I'm really struggling to pass it as a dynamic parameter.

..and if there's an easier way of doing this, I'm all ears!  End of the day, I just need a point to change colors to denote that it's been inspected! Needs to work with the mobile app and in offline mode, which I how I landed on the current workflow.

0 Kudos
DougBrowning
MVP Esteemed Contributor

You have to double encode it for one.  See the help on that.

I also have a feeling you are running into what I posted here  https://community.esri.com/t5/arcgis-field-maps-questions/is-it-possible-to-send-data-back-from-surv...

Basically the URL is made at the beginning so you cant really do a field in the callback since it is too late.  You may be able to hardcode some value not sure.  So just send back like "done" vs a attribute.

I still think not adding to a repeat and instead have a master layer and a related form is the better way to go.

Also you can use Arcade to look for children - which is what I do.  But cannot do symbols.  I know what you are trying to do but it is actually really hard to symbolize that way for now.  We just have the crew mark the point as done in field maps manually for now.

Hope that helps

0 Kudos
PaulPetersen1
Occasional Contributor

yes, that's more or less what I am trying to do! It's crossed my mind that I can't grab an attribute field within the callback (which you've verified). However, another thought is that I should be able to send the {GlobalID} directly from Field Maps, and then that bypasses my need to grab the attribute from Survey123. I can just hard-code the attribute needed to update the point symbology (ie. InspectionStatus='Done')...but I still need to pass the Parent GlobalID as a parameter so that the callback knows which feature to edit. Doesn't work at all the hard-code that!

The following seems to generate a good URL. It does generate the correct GlobalID for the featureID. It just doesn't work in the callback. If you look at the URL being generated by the callback (which I can do if I test in Windows), it actually is a good URL...everything looks correct. But it doesn't actually work. If I just swap out the GlobalID parameter and hard-code it (and keep everything else the same), it works like a champ. It's very frustrating!

arcgis-survey123://?itemID=xxx&field:Pole_Key={GlobalID}&field:PoleNumber={PoleNumber}&field:PoleID={PoleID}&callback:submit=https%3A%2F%2Ffieldmaps.arcgis.app%2F%3FitemID%3Dxxx%26referenceContext%3DupdateFeature%26featureSourceURL%3Dhttps%3A%2F%2Fservices1.arcgis.com%2FdscgdziA6jUxpQJw%2Farcgis%2Frest%2Fservices%2Fxxx%2FFeatureServer%2F0%26featureID%3D{GlobalID}%26featureAttributes%3D%7B%22RetrofitStatus%22%3A%222%22%7D%0A

 

PaulPetersen1
Occasional Contributor

@DougBrowning , this is now solved thanks to Esri Tech Support. I am now able to launch Survey123 from the parent point in FieldMaps, perform the survey on a related child record, and then use the callback to pass an attribute back into the original parent record in Field Maps, thus changing the symbol. Whew.

The tricks were:

  • Configure the URL as an Arcade expression, rather than manually
  • Use the URLEncode() arcade function where relevant, although there is a bug (BUG-000146960) associated with this function that limits its current use
  • Use the arcade expression Mid($feature.globalid,1,36)  to strip out the brackets on the GlobalID value within the featureID parameter of the callback.

So my final arcade expression looked something like shown below. It passes in a hard-coded value of "2" to the "RetrofitStatus" attribute field, which was what controls my layer symbology.

var S123urlsource = 'arcgis-survey123://?itemID=xxxxxx&field:Pole_Key='+$feature.globalid+'&callback:submit=';
var FMurlsource='https://fieldmaps.arcgis.app?';
var FMparams='itemID%3Dxxxxxx%26referenceContext%3DupdateFeature%26featureSourceURL%3Dhttps://services1.arcgis.com/xxxx/arcgis/rest/services/xxxx/FeatureServer/0%26';
var FMGID=Mid($feature.globalid,1,36);
var FMAtt='%26featureAttributes%3D%7B%22RetrofitStatus%22%3A%222%22%7D%0A';
return Concatenate(S123urlsource,UrlEncode(FMurlsource),FMparams,'featureID%3D',FMGID,FMAtt);

YannickCabana
New Contributor

I have a $feature.globalid=dfc3f832-d9d7-4097-91b3-69d10d33fea0 (in lower case in field Maps) and in Survey123, the rel_globalID = {DFC3F832-D9D7-4097-91B3-69D1033FEA0}

Is there a reason why the callback to Field Maps doesn't work  with the FeatureID even if this one is set with $feature.globalid (global id from Field Maps)  initially?  The submit update for the featureAttributes doesn't work.

Thank you for your help!

 

 

 

0 Kudos
DarenThompson
New Contributor

When you pass data back to Field Maps, is it possible to go ahead and have Fieldmaps automatically Submit the data that was passed from Survey123 without manually having to hit that button?

0 Kudos
PaulPetersen1
Occasional Contributor

@DarenThompson , I don't think so.