URL link from related table in popup?

765
9
Jump to solution
07-30-2021 09:32 AM
KellyArmstrong
Occasional Contributor II

I have a related table with a URL field.  I have tried in Arcade to pull those related links and place them in the popup, with no success.  The reason I am trying to do this instead of clicking on the "show related records"  in the popup - is that having crews use this route, is two less clicks for them to navigate out in the field.  They would like the fastest route to be able to click on the URL link.

Any help would be greatly appreciated.

I have attached a screenshot of my related table with fields:

0 Kudos
1 Solution

Accepted Solutions
jcarlson
MVP Frequent Contributor

You can have Arcade generate a linkable URL, but you can't do it in a list.

If your popup is a field list, an expression that evaluates to a URL will show as a list. If your popup is a custom arrangement of HTML, there's no way to return a list of URLs as interactive links, as the expression will evaluate as text.

A workaround (though not an ideal one) is to have a series of expressions that look for "related record X" and return a URL if a record exists at the index value X, otherwise return nothing. In a custom attribute display, you could have all of your expressions appear one after the other.

The big issue with that workaround is that a FeatureSet cannot be sliced by an index the same way an array can. The following code is not pretty, but it works.

var rel = FeatureSetByRelationshipName($feature,"relationshipname", ['url_field'], false)

function get_index(x, fs){
    if(Count(fs) > x){
        var i = 0
        for(var f in fs){
            if(i == x){
                return f['url_field']
            }
            i ++
        }
    }
}

get_index(0, rel)

And you could create a series of expressions, just changing the number in the final get_index function each time.

jcarlson_0-1627666770567.png

Set the text and the URL to the same thing. That way, the link simply won't appear if there is no record at that position.

jcarlson_1-1627666926590.png

Create a long string of expressions in the custom display.

a feature with two related recordsa feature with two related records

a feature with a single related recorda feature with a single related record

I didn't have a URL field, so I just appended the ObjectID to "google.com" to test, but it should work the same.

- Josh Carlson
Kendall County GIS

View solution in original post

9 Replies
jcarlson
MVP Frequent Contributor

You can have Arcade generate a linkable URL, but you can't do it in a list.

If your popup is a field list, an expression that evaluates to a URL will show as a list. If your popup is a custom arrangement of HTML, there's no way to return a list of URLs as interactive links, as the expression will evaluate as text.

A workaround (though not an ideal one) is to have a series of expressions that look for "related record X" and return a URL if a record exists at the index value X, otherwise return nothing. In a custom attribute display, you could have all of your expressions appear one after the other.

The big issue with that workaround is that a FeatureSet cannot be sliced by an index the same way an array can. The following code is not pretty, but it works.

var rel = FeatureSetByRelationshipName($feature,"relationshipname", ['url_field'], false)

function get_index(x, fs){
    if(Count(fs) > x){
        var i = 0
        for(var f in fs){
            if(i == x){
                return f['url_field']
            }
            i ++
        }
    }
}

get_index(0, rel)

And you could create a series of expressions, just changing the number in the final get_index function each time.

jcarlson_0-1627666770567.png

Set the text and the URL to the same thing. That way, the link simply won't appear if there is no record at that position.

jcarlson_1-1627666926590.png

Create a long string of expressions in the custom display.

a feature with two related recordsa feature with two related records

a feature with a single related recorda feature with a single related record

I didn't have a URL field, so I just appended the ObjectID to "google.com" to test, but it should work the same.

- Josh Carlson
Kendall County GIS

View solution in original post

KellyArmstrong
Occasional Contributor II

Josh,

Thank you very much!  I am a newbie at Arcade, but I get this error:

 

KellyArmstrong_0-1627667807768.png

 

0 Kudos
jcarlson
MVP Frequent Contributor

You have an extra ')' in the middle of that first line.

- Josh Carlson
Kendall County GIS
0 Kudos
KellyArmstrong
Occasional Contributor II

Ah ha!  I deleted it and it works great!  Many thanks, on this long Friday!

 

0 Kudos
KellyArmstrong
Occasional Contributor II

Josh,

One more question about this, since my url paths are quite long and they make one scroll in the popup to view all the characters in them.  Is there some way to trim the left 36 characters of the ['media_path'] field?

0 Kudos
jcarlson
MVP Frequent Contributor

Well, you could just put each link on its own line, if that helps. The trouble with shortening the URLs is that the full value is being used for the link text and the URL itself.

To get a separate bit of display text for each link, you'd need the display text to be coming from its own expression. Which is doable, but doubles the number of expressions that the popup is triggering.

You could use the same expression as before, but have it return Right(Count(f['media_path']) - 36) instead.

- Josh Carlson
Kendall County GIS
0 Kudos
KellyArmstrong
Occasional Contributor II

Josh,

I have an interesting observation/question for you.  I followed your above code and it works wonderfully.  The problem I have now, is that when I go back to my expressions and test them, I get an error.  They still function in my webmaps, but when I test them, I get the attached error.  I also can't copy the expression to make another one because of the error.  Did something or an update happen to Arcade for this to no longer function?

 

KellyArmstrong_0-1631631934594.png

 

0 Kudos
KellyArmstrong
Occasional Contributor II

Josh,

Esri must have had a recent update, because as of today, I no longer get any error...

0 Kudos
jcarlson
MVP Frequent Contributor

Oh, good! Sorry I didn't respond to your earlier post, I've been out of the office for the past week. Glad to hear that the error went away on its own, though.

- Josh Carlson
Kendall County GIS
0 Kudos