Field Maps open Survey123 with URL Parameters then referenceContext update status Field Maps

803
5
03-20-2023 03:34 AM
DanielLoegelCMS
New Contributor II

Got a Field Maps that passes URL Parameters to Survey123 that part works great, what I am trying to do is pass the status back to Field Maps using the referenceContext to use updateFeature that the survey is complete. Not sure if it's possible to do this within the URL Parameters.

This is the code I have for the popup in Field Maps.

 

arcgis-survey123://?itemID=xxxxxxxxxxxxxxxxxxxxxxxx&field:SERVICEID=003987464&field:RISERSIZE=5/8"&field:SCHEDULEID=32886552&field:RISERMATERIAL=P&field:EXTENSIONMATERIAL=P&field:PIPEPRESSURE=MP&field:METERLOCATIONCODE=3&field:METERNUMBER=25750178&field:CITY_NM=FOWLER&field:PASTDUEDATE=2023-05-18T19:59:59-04:00&field:SCHEDULEDDATE=2023-04-01T19:59:59-04:00&field:AddressCombined=521 N WALNUT ST, FOWLER, MI&field:TRS_NBR=07041232&field:Inspection_Type=53&field:SEQ_NBR=6736916&field:BUSINESSNAME= &field:PREMISE=7003828008&field:EXTERNALID=6736916&field:CUSTOMERCLASSCD=NULL&field:WHDQ_DSC=LANSING&field:InspectionDesc=53 - Walking - 5YR Steel and Adequate Venting-Previous Insp. Has AC Not Found&field:ParentGlobalID=52e626be-e6d6-4159-80d6-6c7327885c23&center=43.00759271400004,-84.73697497899997&https://fieldmaps.arcgis.app?referenceContext=updateFeature&itemID=8135f507c9da4148bafcaa6595d38331&.../XXXX_3_1_WFL1/FeatureServer/15&featureID=52e626be-e6d6-4159-80d6-6c7327885c23%26featureAttributes%3D%7B%22USER_LeakSurveyComplete%22%3A%22Yes%22%7D%22%3B

0 Kudos
5 Replies
ChristopherCounsell
MVP Regular Contributor

If passing parameters in the callback URL, each parameter's value must be URL encoded, and then the entire callback URL must be encoded (including encoding the values again).

Can you try this with an arcade expression to wrap the parameters + second arcade expression to wrap the entire callback and encoded parameters?

0 Kudos
DanielLoegelCMS
New Contributor II

Been beating on this for the last couple of days. Trying numerous combinations. Wasn't sure if I needed to encode while building the string out (I've tried it without each line encoded and encoding at the end). Here is what I have:

function CreateURLSurvey(lat, lon) {
var url_scheme = "arcgis-survey123://?itemID=<form ID>";
var url = url_scheme + "&field:SERVICEID=" + $feature["USER_SERVICEID"];
var url = url +"&field:RISERSIZE=" + $feature["USER_RISERSIZE"];
var url = url +"&field:SCHEDULEID=" + $feature["USER_SCHEDULEID"];
var url = url +"&field:RISERMATERIAL=" + $feature["USER_RISERMATERIAL"];
var url = url +"&field:EXTENSIONMATERIAL=" + $feature["USER_EXTENSIONMATERIAL"];
var url = url +"&field:PIPEPRESSURE=" + $feature["USER_PIPEPRESSURE"];
var url = url +"&field:METERLOCATIONCODE=" + $feature["USER_METERLOCATIONCODE"];
var url = url +"&field:METERNUMBER=" + $feature["USER_METERNUMBER"];
var url = url +"&field:CITY_NM=" + $feature["USER_CITY_NM"];
var url = url +"&field:PASTDUEDATE=" + $feature["USER_PASTDUEDATE"];
var url = url +"&field:SCHEDULEDDATE=" + $feature["USER_SCHEDULEDDATE"];
var url = url +"&field:AddressCombined=" + $feature["USER_AddressCombined"];
var url = url +"&field:TRS_NBR=" + $feature["USER_TRS_NBR"];
var url = url +"&field:Inspection_Type=" + $feature["USER_Inspection_Type"];
var url = url +"&field:SEQ_NBR=" + $feature["USER_SEQ_NBR"];
var url = url +"&field:BUSINESSNAME=" + $feature["USER_BUSINESSNAME"];
var url = url +"&field:PREMISE=" + $feature["USER_PREMISE"];
var url = url +"&field:EXTERNALID=" + $feature["USER_EXTERNALID"];
var url = url +"&field:CUSTOMERCLASSCD=" + $feature["USER_CUSTOMERCLASSCD"];
var url = url +"&field:WHDQ_DSC=" + $feature["USER_WHDQ_DSC"];
var url = url +"&field:InspectionDesc=" + $feature["USER_InspectionDesc"];
var url = url +"&field:ParentGlobalID=" + $feature["GlobalID"];
// Repeat this line as many times as required based on how many fields you want populated. For this example AssetID will be populated from otherfeatid
var url = url + "&center=" + lat + "," + lon;

var urlFM = UrlEncode("&https://fieldmaps.arcgis.app&referenceContext=updateFeature");
var urlFM = urlFM + UrlEncode("&itemID=<web map itemid>");
var urlFM = urlFM + UrlEncode("&featureSourceURL=https://services.arcgis.com/xxxxxxx/arcgis/rest/services/LS_Owosso_Field_Maps_WFL1/FeatureServer/1");
var urlFM = urlFM + UrlEncode("&featureID=");
var globalID = $feature["GlobalID"];
var urlFM = urlFM + UrlEncode(globalID);
var urlFM = urlFM + UrlEncode("&featureAttributes={'USER_LeakSurveyComplete':'Yes'}");
var urlFM = urlFM + UrlEncode("&callback=https://fieldmaps.arcgis.app");
var urlFM = UrlEncode(urlFM);
var url = url + urlFM;
return url;
}

If I encode the entire url the Survey123 doesn't open at all.

Missing something somewhere.

Thanks for the help

0 Kudos
ChristopherCounsell
MVP Regular Contributor

If this is a URL from Survey123>FieldMaps>FieldMaps, it looks like you've gotten two calls to fieldmaps?

It should have the callback as the last Survey123 URL parameter, with the FM parameters after e.g.:

https://survey123.arcgis.app?itemID=36ff9e8c13e042a58cfce4ad87f55d19&callback=https://quickcapture.arcgis.app?itemID=867895a71a1840399476fc717e76bb43

arcgis-survey123://?portalUrl=https://www.arcgis.com&itemID=6e9276bfdf164a2bafa236f40a1eb4f8&callback=https://fieldmaps.arcgis.app...

 

0 Kudos
DanielLoegelCMS
New Contributor II

First off thanks for your help.

The workflow starts in Field Maps, user selects the meter location on the map and this is the popup is configured on Field Map with the url link to Survey123, passing the parameters that are required for Survey123, users submit the survey and was looking to pass back to the feature in Field Maps that the survey is complete. Its Field Maps > Survey123 > Field Maps

I did try moving around the callback to before and after the referenceContext code with the same results. If comment out the referenceContext code section and just have the callback at the end it works correctly as it did before switching back to Field Maps after a submit.

This code, will not switch back to Field Maps, it stays on Survey123.

function CreateURLSurvey(lat, lon) {
var url_scheme = "arcgis-survey123://?itemID=xxxxxxxxxxxxxxxxxxxxxxxxx";
var url = url_scheme + "&field:SERVICEID=" + $feature["USER_SERVICEID"];
var url = url +"&field:RISERSIZE=" + $feature["USER_RISERSIZE"];
var url = url +"&field:SCHEDULEID=" + $feature["USER_SCHEDULEID"];
var url = url +"&field:RISERMATERIAL=" + $feature["USER_RISERMATERIAL"];
var url = url +"&field:EXTENSIONMATERIAL=" + $feature["USER_EXTENSIONMATERIAL"];
var url = url +"&field:PIPEPRESSURE=" + $feature["USER_PIPEPRESSURE"];
var url = url +"&field:METERLOCATIONCODE=" + $feature["USER_METERLOCATIONCODE"];
var url = url +"&field:METERNUMBER=" + $feature["USER_METERNUMBER"];
var url = url +"&field:CITY_NM=" + $feature["USER_CITY_NM"];
var url = url +"&field:PASTDUEDATE=" + $feature["USER_PASTDUEDATE"];
var url = url +"&field:SCHEDULEDDATE=" + $feature["USER_SCHEDULEDDATE"];
var url = url +"&field:AddressCombined=" + $feature["USER_AddressCombined"];
var url = url +"&field:TRS_NBR=" + $feature["USER_TRS_NBR"];
var url = url +"&field:Inspection_Type=" + $feature["USER_Inspection_Type"];
var url = url +"&field:SEQ_NBR=" + $feature["USER_SEQ_NBR"];
var url = url +"&field:BUSINESSNAME=" + $feature["USER_BUSINESSNAME"];
var url = url +"&field:PREMISE=" + $feature["USER_PREMISE"];
var url = url +"&field:EXTERNALID=" + $feature["USER_EXTERNALID"];
var url = url +"&field:CUSTOMERCLASSCD=" + $feature["USER_CUSTOMERCLASSCD"];
var url = url +"&field:WHDQ_DSC=" + $feature["USER_WHDQ_DSC"];
var url = url +"&field:InspectionDesc=" + $feature["USER_InspectionDesc"];
var url = url +"&field:ParentGlobalID=" + $feature["GlobalID"];
var url = url + "&center=" + lat + "," + lon;
var url = url + "&callback=https://fieldmaps.arcgis.app";

var urlFM = UrlEncode("&https://fieldmaps.arcgis.app&referenceContext=updateFeature");
var urlFM = urlFM + UrlEncode("&itemID=xxxxxxxxxxxxxxx0af2c3d934bc2");
var urlFM = urlFM + UrlEncode("&featureSourceURL=https://services.arcgis.com/xxxxxxxxxx/arcgis/rest/services/LS_Owosso_Field_Maps_WFL1/FeatureServer/...");
var urlFM = urlFM + UrlEncode("&featureID=");
var globalID = $feature["GlobalID"];
var urlFM = urlFM + UrlEncode(globalID);
var urlFM = urlFM + UrlEncode("&featureAttributes={'USER_LeakSurveyComplete':'Yes'}");

var urlFM = UrlEncode(urlFM);
var url = url + urlFM;
return url;

Thanks

Dan

0 Kudos
ChristopherCounsell
MVP Regular Contributor

I understand your workflow. I mean that you have two calls to the fieldmaps app? Popup>Survey123>FieldMaps>FieldMaps?

why is https://fieldmaps.arcgis.app listed twice?

 

var url = url +"&field:ParentGlobalID=" + $feature["GlobalID"];
var url = url + "&center=" + lat + "," + lon;
var url = url + "&callback=https://fieldmaps.arcgis.app";

var urlFM = UrlEncode("&https://fieldmaps.arcgis.app&referenceContext=updateFeature");
var urlFM = urlFM + UrlEncode("&itemID=xxxxxxxxxxxxxxx0af2c3d934bc2");
var urlFM = urlFM + UrlEncode("&featureSourceURL=https://services.arcgis.com/xxxxxxxxxx/arcgis/rest/services/LS_Owosso_Field_Maps_WFL1/FeatureServer/...");
var urlFM = urlFM + UrlEncode("&featureID=");
var globalID = $feature["GlobalID"];
var urlFM = urlFM + UrlEncode(globalID);
var urlFM = urlFM + UrlEncode("&featureAttributes={'USER_LeakSurveyComplete':'Yes'}");

var urlFM = UrlEncode(urlFM);
var url = url + urlFM;
return url;

0 Kudos