Select to view content in your preferred language

Create direct link to add related records in Field Maps

2075
8
Jump to solution
04-17-2024 07:23 AM
ajohnson_wsb
Occasional Contributor

I'm looking to simplify the way that users have to add related records in Field Maps. I know that on the parent asset, a user can click the related link at the bottom and then click Add, etc. but I am looking to give users a "button" or something so that they can directly open a new related record. The goal is to limit how many times users have to click through boxes when adding new related records

At the Dev Summit last month, Esri showed a way to do this with Arcade and HTML but the presentation missed pieces in the demo that showed all of the code in order to replicate. Recording of the presentation is below:

https://registration.esri.com/flow/esri/24epcdev/deveventportal/page/detailed-agenda/session/1699036...

If anyone has successfully done this please let me know. Thank you!

1 Solution

Accepted Solutions
ajohnson_wsb
Occasional Contributor

I was able to get a resolution for this workflow, many thanks to meeting with the Field Maps Team during the Esri UC. First this workflow is described on Field Maps documentation that I missed previously.

ajohnson_wsb_0-1721827438585.png

https://doc.arcgis.com/en/field-maps/latest/prepare-maps/deploy-your-map.htm#ESRI_SECTION1_F7DE2402B...

Here is my final arcade expression that works. In my case, one issue I was having was the curly brackets of my GlobalID field were being "pushed" into the uuid field of my child record table and Field Maps adds those curly brackets already so the link failed without stripping the curly brackets as seen below.

var itemID = //item id of web map;
var featureSourceURL = //feature service url of parent asset
var featureID = Replace(Replace($feature.GlobalID, "{", ""), "}", "") //globalid field of parent asset, with stripping of curly brackets
var foreignKeyField = 'GlobalID' //globalid field of parent asset
var referenceContext = 'addRelatedFeature'

var values = 'referenceContext='+referenceContext+'&itemID='+itemID+'&featureSourceURL='+featureSourceURL+'&featureID='+featureID+'&foreignKeyField='+foreignKeyField

var url = "https://fieldmaps.arcgis.app/?" + values;


return url

 

I was never able to get the html button to work like @KeitherPerkinsWSB described. I got the same error message of "Unable to add layer". To get around this and still have a clean button for staff (instead of the long url), I added a text box and created a hyperlink to the expression field.

ajohnson_wsb_1-1721827854490.png

 

View solution in original post

8 Replies
ChristineTombleson1
Frequent Contributor

I have the same question!  I have many related tables and would love to be able to create my own button instead of the user having to go in an use the Add button. I appreciate you sharing the Dev Summit link but unfortunately if you did not register to go to the Summit, you can't access it. I couldn't access it with just my ESRI username and password.  

0 Kudos
Teresa_Blader
Frequent Contributor

Teresa_Blader_0-1713558381233.png

Teresa_Blader_1-1713558471640.png

I think the main thing left out of the video is the rest of the URL parameter in the values variable as well as the HTML code for the button in the URL parameters. I think Kevin was going to do a blog at some point. I'm also working on this these days 🙂 But I haven't attempted yet. 

@KevinBurke 

Teresa Blader
Olmsted County GIS
GIS Analyst - GIS Solutions
ajohnson_wsb
Occasional Contributor

Video of Esri performing this workflow is now publicly available here: https://mediaspace.esri.com/media/t/1_v2ev8meu

0 Kudos
KeitherPerkinsWSB
Emerging Contributor

I am also seeing some odd behavior with the HTML configuration for the button from this code. I replicated the HTML portion from this demo to add a button simply pointed at https://google.com for now. When the Arcade expression is present in the webmap it appears in my pop up and is functional. However, when trying to save the map I get the below error. 

If I remove the Arcade Expression, the map saves. I cannot seem to find anything where this html code is not supported. Any insight here would be great.

KeitherPerkinsWSB_0-1717535727043.png

It also presents itself as a 403 error in the F12 console where it looks like the map config cannot be written to the Portal Directory.

I have stripped everything out of the webmap except this single layer, and have the popup config to only have this arcade expression but same save error in a fresh map as well.

KeitherPerkinsWSB_1-1717535866347.png

 

//Temp URL for testing button

var url = "https://www.google.com"

//HTML button to trigger url

return{
  type : 'text',
  text : `  <div style="padding: 0px 0px;">
  <table style=" border-collapse: separate; border-spacing: 0px 0px; width: 100%; table-layout: fixed; margin-bottom: 8px;">
    <tbody>
       <tr>
      <td style="text-align: center; width: 100%">
        <a href="${URL}" target="_blank" style="background-color:#00304d;color:#FFFFFF;display:block;margin:0px auto;padding:10px;text-decoration:none;valign:center;width:220px;">MV Cable</a>
      </td>
       </tr>
    </tbody>
  </table>
</div>
  `
}

 

ajohnson_wsb
Occasional Contributor

I was able to get a resolution for this workflow, many thanks to meeting with the Field Maps Team during the Esri UC. First this workflow is described on Field Maps documentation that I missed previously.

ajohnson_wsb_0-1721827438585.png

https://doc.arcgis.com/en/field-maps/latest/prepare-maps/deploy-your-map.htm#ESRI_SECTION1_F7DE2402B...

Here is my final arcade expression that works. In my case, one issue I was having was the curly brackets of my GlobalID field were being "pushed" into the uuid field of my child record table and Field Maps adds those curly brackets already so the link failed without stripping the curly brackets as seen below.

var itemID = //item id of web map;
var featureSourceURL = //feature service url of parent asset
var featureID = Replace(Replace($feature.GlobalID, "{", ""), "}", "") //globalid field of parent asset, with stripping of curly brackets
var foreignKeyField = 'GlobalID' //globalid field of parent asset
var referenceContext = 'addRelatedFeature'

var values = 'referenceContext='+referenceContext+'&itemID='+itemID+'&featureSourceURL='+featureSourceURL+'&featureID='+featureID+'&foreignKeyField='+foreignKeyField

var url = "https://fieldmaps.arcgis.app/?" + values;


return url

 

I was never able to get the html button to work like @KeitherPerkinsWSB described. I got the same error message of "Unable to add layer". To get around this and still have a clean button for staff (instead of the long url), I added a text box and created a hyperlink to the expression field.

ajohnson_wsb_1-1721827854490.png

 

ahargreaves_FW
Frequent Contributor

@ajohnson_wsb thanks for providing this!

0 Kudos
ZachBodenner
MVP Regular Contributor

I've been able to get almost everything working except for my Field Maps to actually open up the related record add.

var itemID = 'a271a7a9e82340bc831fd54691b9335e';
var featureSourceURL = 'https://gis.edenprairie.org/maps/rest/services/Internal/NRManagement/FeatureServer/1'
var featureID = Replace(Replace($feature.GlobalID, "{", ""), "}", "") //globalid field of parent asset, with stripping of curly brackets

console (featureID)
var foreignKeyField = 'GlobalID' //globalid field of parent asset
var referenceContext = 'addRelatedFeature'

var values = `referenceContext=${referenceContext}&itemID=${itemID}&featureSourceURL=${featureSourceURL}&featureID=${featureID}&foreignKeyField=${foreignKeyField}`

var url = "https://fieldmaps.arcgis.app/?"+values

var btn =   
  `
    <div align="center">
      <a href="${url}" style="background-color:#3699ff;color:#ffffff;padding:5px; border-radius:10px;text-decoration:none;display:inline-block;text-align:center;" >
          <b>add related record</b>
      </a>
  </div>

  `
console (url)


return { 
	type : 'text', 
	text : btn
}

 

Using this code I'm able to pop open the correct map, with the correct feature selected and zoomed to, popup opened, but no related record add. No errors either, so I can't quite pin down the issue. Has anyone else run into that particular case? 

Happy mapping,
- Zach
0 Kudos
LeighStarr
Emerging Contributor

I am getting an error: "The specified foreign key field couldn't be found". 

I am a little confused... there isn't anything pointing to the child in the relationship.  Everything points to the parent, including the source URL.  I would have thought that the foreign key would point to the child, but the comments clearly state parent...

For the relate, both are branch versioned, with the Primary Key of the Parent feature class: 'GlobalID', and the Foreign key in related feature class: 'CAB_GUIID'

With the parent primary key as 'GlobalID' my entry into the expression builder is:

var featureID = Replace(Replace($feature.GlobalID, "{", ""), "}", "")  //GlobalID field of parent asset
var foreignKeyField = 'GlobalID';   //GlobalID field of parent asset
 
On a somewhat related note, if I have multiple relates, how would it know which one to add?
What am I missing here?
0 Kudos