Select to view content in your preferred language

'Relationship not found in the map' error

1413
11
Jump to solution
10-26-2023 12:59 PM
Paco
by
Occasional Contributor

Hello all!

I am trying to access Related tables in an AGOL Hosted FeatureLayer using JSAPI(4.27) for display in a Popup.

I have tried adjusting the "Browse related records in a popup" code sample,  but am getting 'Relationship not found in the map' error in the popup.

I have added the FeatureLayer and the table as FeatureLayer and have used the "type: relationship" and the "relationshipID" found in the table service,  but still get the error. I have also 'loaded' the table per the sample.

if I use the new AGOL MapViewer 'Relationship' in the popup,  it does see the Related table fields.  any reason why I am not seeing them in my app?  

thx again!

0 Kudos
1 Solution

Accepted Solutions
LaurenBoyd
Esri Contributor

Here is an example application that shows how to display related data information within the selected feature's popup using ExpressionContent: https://codepen.io/laurenb14/pen/xxMOqgr?editors=1000

It's using Arcade's FeatureSetByRelationshipName to get that related data and loop through the related features to print out an attribute in a list. Just select one of the National Park boundaries to see a list of related trails (which participates in a relationship with the NP boundaries layer) that is not added to the map.

Hope this helps!

Lauren

View solution in original post

11 Replies
Paco
by
Occasional Contributor

Paco_0-1698350726800.png

 

0 Kudos
Paco
by
Occasional Contributor

Okay,  now I'm uncertain which relationshipID: to use?   I was using '6' now ive tried '1' and the popup now shows a blank area and the relationship arrow that opens a blank/black area.   soooo,  first of all,  which ID number am i using for my Relationship table?  one shows an error,  the other shows a blank.   thx!

Paco_0-1698353292182.png

 

0 Kudos
LaurenBoyd
Esri Contributor

@Paco The number next to the relationship name is the relationship ID (outlined in red below). The purple outlined numbers are the layer IDs that participate in that relationship with the current layer you are viewing:

relationshipIDs.png

I would confirm you have the correct relationship ID configured along with the corresponding related data added/loaded into the map as a table or layer depending if it's non-spatial or spatial respectively.

 

Lauren
Paco
by
Occasional Contributor

Thanks for the support @LaurenBoyd !   worked my way thru those Relationship numbers and finally got the Table connection showing in the popup.

Now,  is there any way to simply show some of those related attributes in the initial text popup,  and Not on the second relate window in the popup?  I don't really understand the need for second click to open those related values?   if I use my popupTemplate from my Feature popup as my template for my Related Table, it does not show in the initial popup, but Does show in the related popup click window.  see my popup here- 

first click Popup(missing 'Age')

Paco_0-1698424126435.png

second  'relate' click Popup(showing related 'Age' value)

Paco_1-1698424283401.png

 

0 Kudos
Paco
by
Occasional Contributor

..or,  am I coming to the conclusion that using Related Tables and popups when building JS web applications is a bad idea?   Is permanently Joining Tables to my FeatureClasses/Services the better way to go so I dont have these interesting popup and attribute access issues?

What do we all think?  🙂

thx!

0 Kudos
LaurenBoyd
Esri Contributor

@Paco if you just want to display information from the related data within the selected feature's popup and not display a list of related features to select and drill into, then you could always use ExpressionContent to display related data information as a popup element. Here's an example of Arcade that grabs related data of the current selected feature and builds a table: https://community.esri.com/t5/arcgis-online-questions/display-related-records-in-a-popup-in-a-nice-t... 

Using related tables with popups is definitely encouraged, you have a lot of options on how you want to display related data. It is just about finding the best way for your use case 😊

Lauren
0 Kudos
Paco
by
Occasional Contributor

Thanks @LaurenBoyd .    I see the Post is using "FeatureSetByRelationshipName" Arcade statement?  I'll look closer hopefully that will help.  But im still surprised how very close I am to what I need,  but I just cant move my Relationship content to my original popup?  

Im using these simple "content:" parameters in my popupTemplate,  but it still seems to separate the Popup content into 'feature attributes' and 'relationship attributes' as my previous screenshot showed?   Im hoping I just have the order wrong,  or need to move the content "type:" somewhere else?  the Text type works well with HTML so im trying to stay within that world for the Popup output.   here is my section of code-

const bedrockPopup = {
    "title": "Bedrock Polygon Geology",
    content:
    [
        {
            type: "text",
            text: "<br><b>Map Unit:</b> <i>{UnitCode}</i><br><br><b>Full Name:</b> <i>{FullName}</i><br><br><b>Age:</b> <i>{Age}</i>",
        },
        {
            type: "relationship",
            relationshipId: 1,
            displayCount: 1,
        }
    ]
0 Kudos
LaurenBoyd
Esri Contributor

If you're wanting to show the list of related records from the selected feature's popup, the RelationshipContent allows you to display a list to drill down into the related record's popup templates themselves. Relationship content does not let you display all content from the related record's popup template in the list, only the title and a field you want to order the list by.

For example, the Browse related records sample shows the extent of what can be displayed in the RelationshipContent. The following image is the RelationshipContent element itself:

LaurenBoyd_0-1698771674959.png

The orderByFields will display a field from the related data.

// Create RelationshipContent with the relationship between the units and fires.
{
  type: "relationship",
  // The numeric ID value for the defined relationship on the service.
  // This can be found on the service.
  relationshipId: 2,
  description: "Fires that {UNIT} responded to from 2017-2021 ordered by most to least acreage burned.",
  // Display two related fire features in the list of related features.
  displayCount: 2,
  title: "Fires",
  // Order the related features by the 'GIS_ACRES' in descending order.
  orderByFields: {
    field: "GIS_ACRES",
    order: "desc"
  }
}

If you want to just display text from your related data in the original popup and not a list of related records you can drill down into and view individually, you can use the ExpresssionContent as mentioned in my previous comment.

Lauren
0 Kudos
Paco
by
Occasional Contributor

Thanks again for your response Lauren.   Yes, I only want display text from a Related Table to my original Popup.  which I can accomplish easily by permanently Joining the Table to my Feature.   But I am still confused as to how the ExpressionContent can access the Related Table(relationshipID: 1) without adding a 'type: relationship' to the content parameters?

the example doesn't explain a Table Relationship.  and some examples show using literals like backticks, and some dont for the Arcade statements?  

I would love to see a very simple example of Relating a Table to a Feature Service Layer, and displaying some of the attributes from that Table in a Popup,  without the drill-down tabs.

I don't really want to Join Tables each time I update the dataset,  just for a simple Popup  😞

* I included a very satisfying Popup of what Im looking for, but using a Joined Table version of the FeatureLayer. "Age" is an attribute from the original Related Table.

Thanks!    (sadly i've been seeing a few other posts regarding the difficulty of displaying Related Table attributes in Popups/without drill-down..  hoping theres a solution! thumbs up!)

Paco_0-1698782063435.jpeg

 

0 Kudos