autocomplete search("name?url=https://services1.arcgis.com/1acZBnEF9zjV0l5X/arcgis/rest/services/Test/FeatureServer/0")
But how do I populate my Foreign Key within the Survey in the related table automatically based on the building selection?
Thanks
@IsmaelChiviteI accomplished this using a piece of javascript and this in the calculation field:
pulldata("@javascript","get_globalid.js", "findCode", 'https://services1.arcgis.com/1acZBnEF9zjV0l5X/arcgis/rest/services/Building_Data_Test3/FeatureServer/0', string(${NAME}), 'GlobalID')
Thanks for your suggestion!
Have you considered using the Inbox for this?
Through the Inbox, you will be able to display (and filter) all buildings as a list and also as a map. Selecting a building from the list or map will open the survey for that building. Adding a new row into the buildings inspection repeat will automatically add your inspection as a related record.
Thanks @IsmaelChivite for the quick response. I have never tried the Inbox before. I don't really want to have the user select the building spatially, just from a drop down. Do you have a link to any examples of how this can be done using an existing feature service and related tables?
@DarrylKlassen1 , is there any way you could share the get_globalid.js code? I'm trying to do the *exact* same workflow! No worries if it's not possible.
Hi @Olwyn_Bruce , I have attached the code here:
/* * JavaScript functions for Survey123 */ function findCode2(layerURL, userinput, field, token) { return "OUTVALUE"; } function findCode(layerURL, userinput, field, token){ // Output value. Initially set to an empty string (XLSForm null) let outValue = ""; // Check to make sure both layerURL and location are provided if (layerURL == null || layerURL === "") { // The function can't go forward; exit with the empty value } // Set up query parameters let f = "f=pjson"; let where = "where=NAME="+"'"+userinput+"'"; let outFields = `outFields=`+field; let returnGeometry = "returnGeometry=false"; let parameters = [f, where, outFields, returnGeometry].join("&"); if (token) { parameters = parameters + `&token=${token}`; } let url = `${layerURL}/query?${parameters}`; // return url; // Create the request object let xhr = new XMLHttpRequest(); // Make the request. Note the 3rd parameter, which makes this a synchronous request xhr.open("GET", url, false); xhr.send(); let mylen = 0 // Process the result // This an abbreviated version without being able to distinguish different types of errors if (xhr.status === 200) { let response = JSON.parse(xhr.responseText); if (!response.error) { if (response.features[0]) { outValue = response.features[0].attributes[field]; mylen = 1 } } } return outValue; }
Brilliant thank you for saving me the time!! Much appreciated.
This is pure gold. Thank you so much @DarrylKlassen1.
Hello,
Adding onto this 2.5 years later in case anyone else has run into this issue... I could not get the JavaScript to work for me at all. I ended up using the pulldata(@layer... code instead, following this video: https://www.youtube.com/watch?v=sSjr8KV1HLc
I hope this helps someone else!
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.