Select to view content in your preferred language

Arcade Expression to reopen submitted Survey 123 surveys to edit and update.

276
3
09-29-2025 12:26 PM
RachaelMurtaugh
Frequent Contributor

I have a hosted feature layer of signal light locations with a related table of inspections and maintenance. What I need to be able to do is allow the user to reopen a submitted form from Field Maps. The survey was created in Survey 123 Connect from the hosted feature layer, and currently users can click on a signal and hit a URL linked text that opens the survey with the signal's data prepopulated. 

The challenge is, I need to be able to reopen either the most recent form or be able to sort forms that have the response of either "Need minor repair" or "Needs major repair." for each signal, reopen them in Survey 123 and edit, and then resubmit them. Below is my code so far, thanks to another Community Member, but I still can't get it to work. 

When I click on the Linked Text for the Pop-up for the singal layer, it tries to open the Survey Inbox, but I get the error Code 400, Cannot perform query. Invalid query parameters. In the Survey 123 spreadsheet. I have the following in the bind::esri:parameters query="1=1&orderByFields=InspectionStartTime DESC" allowUpdates=true 

 

var urlsource = 'arcgis-survey123://?';
var inspection = FeatureSetByRelationshipName($feature, 'SignalInspection',['GUID','InspectionStartTime'], false);
var insp_count = Count(inspection);

if (insp_count==0) {
   var recmess = Text("Create New Record");
   var glid = '';
   var params = {
      itemID: 'b5ad40b0c8014d7c92715d1fb65a2de1',
      action: 'collect',
      "field:GUID": $feature["GlobalID"]
      };
return urlsource + UrlEncode(params)+ glid;

   }
else {
   for (var rec in inspection){
      var recmess = Text("Edit Existing Inspection");
      var glid = Text("&q:where=GUID=" + "%27" + $feature.GlobalID + "%27");
      var params = {
         action: 'edit',
         folder: 'inbox',
         itemID: 'b5ad40b0c8014d7c92715d1fb65a2de1',
         update: 'true',
   };
   }
}
   return urlsource + UrlEncode(params)+ glid;
   
0 Kudos
3 Replies
Neal_t_k
Frequent Contributor

@RachaelMurtaugh Instead of ordering the repeats have you tried to filter them to just "Need minor repair" or "Needs major repair."

query="Status IN ('Need minor repair','Needs major repair')"

or 

query="Status = 'Need minor repair' OR Status = 'Needs major repair'"  

0 Kudos
AndrewPadilla
Frequent Contributor

Hi @RachaelMurtaugh, I currently have a similar pop-up in Field Maps that checks the inbox for a survey and if one doesn't exist it opens up a new survey with a few pre-populated fields and returns back to Field Maps upon submission of the survey.  If you only expect one survey for each point I think my code my be helpful. However, if you conduct mutliple surveys for each point then the best way to filter for the  Need minor repair" or "Needs major repair." would be using the Survey123 inbox query as @Neal_t_k suggested. I have my inbox filtering for the current year since I only want people editing this years data. 

Two issues I was able to overcome with the Field Maps to Survey123 callback:

  • I found that I had to make sure globalids were standardized prior to looking up surveys in the inbox.
  • In addition, I found that the call back had to be manually assembled instead of using UrlEncode().

I added the code below to an Arcade Expression in my Web Map in the pop up. Please note anything in bold text should be replaced with your values.  I hope this helps, callbacks can be frustrating but super helpful when they work.

Below is the code for my circumstance:

 

var urlsource = 'arcgis-survey123://?';

var itemID = '<your survey123 item ID here>'; // Replace annually

// --- Normalize the stored survey GlobalID (uppercase, no braces). Make sure your globalID names match
var globalid = Text(DefaultValue($feature.<globalId_survey>, ''));
if (!IsEmpty(globalid)) {
  globalid = Replace(globalid, '{', '');
  globalid = Replace(globalid, '}', '');
  globalid = Upper(globalid);
}

// --- Sanitize polygon GlobalID for featureID in callback
var fglobalid = Text(DefaultValue($feature.<globalId_point>, ''));
if (!IsEmpty(fglobalid)) {
  fglobalid = Upper(Replace(Replace(fglobalid, '{', ''), '}', ''));
}

// --- Build the callback string manually (&callback=submit=...)
//     Each inner "&" becomes "%26"
var callback =
  + '%26itemID=<your fieldmaps item id here>'
+ '%26featureSourceURL=https://services.arcgis.com/<YourAgencyID>/arcgis/rest/services/<YourFeatureServiceNameHere>/FeatureServer/0' //Make sure the number is correct but typically 0
  + '%26featureID=' + fglobalid
  + '%26featureAttributes=' + UrlEncode('{"<ConditionSurvey>":"<Surveyed>"}'); //After survey was submitted and callback returned to Field Maps populated one field (used to style symbology of my polygon as complete) I was only able to manually assign a value, not a field value.

// Check if survey exists (GlobalID is not empty)
var surveyExists = !IsEmpty(globalid);

// Initialize the final URL
var finalUrl;
if (surveyExists) {
    // Open an existing survey for editing
    finalUrl = urlsource +
        'itemID=' + itemID +
        '&action=edit' +
        '&q:globalId=' + globalid +  // normalized to uppercase, no braces
        '&folder=inbox' +
        '&update=true' +
        '&callback=' + callback;  
} else {
    // Open a new survey and prefill fields (change as needed. The &field: <fieldName> are the names in Survey123)
    finalUrl = urlsource +
        'itemID=' + itemID +
        '&action=collect' +
        '&callback=' + callback +  
        '&field:geoGUID=' + $feature.UUID +  
        '&field:InterviewedCal=' + $feature.name_id +  
        '&field:SurveyFormType=1' +  
        '&field:ConfirmSurvey=1';  
}

// Return the final clickable link
return {
  type: 'text',
  text: '<a href="' + finalUrl + '" style="display:inline-block; padding:15px 20px; font-size:16px; font-weight:bold; color:#ffffff; background-color:#440154; border-radius:5px; text-decoration:none; text-align:center;">Open Survey</a>'
};
0 Kudos
RachaelMurtaugh
Frequent Contributor

I will hang onto this for sure. I'm currently exploring Field Tasks and Forms to see if this will give me a more streamlined option for this.