Get 1:M related objects using Arcade

11629
25
02-01-2019 04:44 PM
LindsyHales_Bentley
New Contributor III

Branched from: https://community.esri.com/thread/196867-get-related-objects-in-arcade 

I have a pipeline fc with geometry(fittings are drawn to scale as a polygon) with diameter, and globalid fields. 

And then a view(table) containing asset name, attribute value, and a GISid.

This is a one-to-many relationship (GISid = globalid) because a section of pipe could have multiple materials (inner, outer, encasement, coatings, etc.).

I want to show the related information in the pop-up of the pipeline.

25 Replies
XanderBakker
Esri Esteemed Contributor

I don't see anything wrong with the expression, so I think the source data might be the problem, although it is strange that the error points to the $map. What you can do is extract a small part of the data of the service and publish it to ArcGIS Online to test and see if that works (it should). The other aspect is the fact that you are using a map service and not a feature service. Not sure if that could cause the problem.

0 Kudos
deleted-user--MMnVrog9xw_
Occasional Contributor

I just tested with a feature service of the same data from the server and it now accepts it as a valid expression. So looks like map service is not supported. Thanks for your help

deleted-user--MMnVrog9xw_
Occasional Contributor

EDIT: I removed the other map service that I had in the map and the pop-up is now working! I guess it may have been getting confused with the two different tables even though they had different names

The expression seems to be valid now, when I click test in the expression builder it returns what I would expect. Also when I look at the network traffic through the dev console when clicking on a feature I can see the query going out and returning valid features. However, I can't get anything to actually display in the pop-up. Do you see any reason why this would not work? I also tried the custom attribute display with the field but that didn't work either.

0 Kudos
IvanGnevanov
New Contributor III

Hi, I have the same issue with Portal for ArcGIS 10.7.1 when trying to add a custom attribute to a layer in a Web Map layer (POL for example). I am not able to reference $map Global variable since Globals only include $feature.* fields. I have no other layers in my map so I can't remove something to check.

When I am trying to setup a popup for separately added related table, it allows to reference all the variables from the example ($map, $layer, $datastore, etc.).

Jefcoat_Nathan
New Contributor III

Just want to say thanks for this. Saved me some time!

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi Jefcoat, Nathan ,

Glad to hear that this discussion has helped you. Just to add some exiting news (in ArcGIS Online) for getting to related records: the new function "FeatureSetByRelationshipName": https://developers.arcgis.com/arcade/function-reference/data_functions/#featuresetbyrelationshipname which allows for a faster and easier way to access related records.

See also this blog: What’s New in Arcade 1.8 

0 Kudos
JérémiePedoia
New Contributor III

HiXander Bakker

Thank you for this really helpfull code.

Is there a way to include a unique url link by asset ?

Is it possible to build a link based on the globalID of each related record in the main feature popup ?

Thanks in advance.

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi Jérémie Pedoia ,

This is possible, yes! Is it easy? Not even close... 

Let me try and explain why this is the case. With Arcade you cannot construct HTML. Any HTML you construct will be returned and interpreted as text and parts might even be purged from the result. So, with Arcade you could create a list of URLs of all assets, but this will be presented as a text and not clickable URLs. You can use Arcade and create the list of A tags with the links to the assets but this will still be text and does not provide clickable links to the assets. 

You can do this, but this would be require a huge amount of separate Arcade expressions inside a custom html pop-up. I really don't recommend you to go there. Hopefully, in the near feature it will be possible to generate HTML with Arcade that is actual usable in a pop-up.

JérémiePedoia
New Contributor III

Hi Xander Bakker,

Thank you for your answer.

I can't wait to generate HTML with Arcade.

As I know that there will be max 5-6 related records, I prepared 10 links with display fonctionnality.

I had to make 20 Arcade expression for that but I works and works only because there are only ten.

Thanks again for sharing.

J.

AhmadSALEH1
Occasional Contributor III

Xander Bakker‌ is there a way to change the change the returned sting color ?