Arcade, FeatureSets, and Popups

4912
22
Jump to solution
09-16-2020 01:34 PM
AndrewSD
Occasional Contributor

Hello,

I have two layers, Organization and Venue in a web map. 

I want to display Venue info in a popup on the Organization layer. I know I can use FeatureSetByName in Arcade, but I don’t have a lot of experience with Arcade.

 

There are also related records so if you click on an Organization point it could have several venues so I would like to display all that relate to the Organization name (how they are related).

In my head I imagine the popup having all the organization info (name, address, other features) that I have created in the customize popup interface. Then I would have an Arcade Expression that gave me the venue name, address, etc. This expression would show any related venue that an Organization has worked at. 

If anyone can give a sample code that would be great. If you need more info I can provide it just not sure what one might need. 

Thank you!

1 Solution

Accepted Solutions
XanderBakker
Esri Esteemed Contributor

Hi ANDREW BUTTERFIELD ,

It seems that there is something strange going on in your data. I was expecting to find a relationship from the organizations info to the venue locations, but I only found one relationship towards Form_2. And when I try to use it, it returned an empty string as the relationship name:

Earlier you mentioned that the link between the two layers is established using the organization name, so I used that instead. have a look at the expression below:

// use organization name and venue name to link the information
var orgname = $feature["org_name"];

// access the venue featureset
var fsvenues = FeatureSetByName($map,"Venue Locations", ["org_venue", "org_venue_address", "org_venue_type"], False);

// create a SQL query to get the related venues
var sql = "org_name = @orgname";

// filter venues on org name / venue location
var venues = Filter(fsvenues, sql);

// count venues
var cnt = Count(venues);

// loop through venues and create result
var result = "";
if (cnt > 0) {
    // there are venues found, loop through venues
    result = cnt + " venues found:"
    for (var venue in venues) {
        // add venue information to the result
        result += TextFormatting.NewLine + TextFormatting.NewLine + venue["org_venue"];
        result += TextFormatting.NewLine + venue["org_venue_type"];
        result += TextFormatting.NewLine + venue["org_venue_address"];
    }
    
} else {
    // no venues found
    result = "no venues found...";
}

return result;

‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

The result will show like this:

Is this what you are after?

View solution in original post

22 Replies
XanderBakker
Esri Esteemed Contributor

Hi ANDREW BUTTERFIELD , 

See below a simple example based on what you described:

// user clicked on organization, so that will be your $feature
// get related venue records, change name of relationship and fields according to your data
var fsvenues = FeatureSetByRelationshipName($feature, "Name of the relationship to access venue", ["name", "address"], False);

// initialize result text and get count
var result = "";
var cnt = Count(fsvenues);

// check count and start creating result text
if (cnt > 0) {
    // we have related records
    result = cnt + " venues found:";
    // loop through venues
    for (var venue in fsvenues) {
        // add a line per venue and include name and address
        result += TextFormatting.NewLine + " - " + venue["name"] + " (" + venue["address"] + ")";
    }
} else {
    // we don't have related record, show that in the result
    result = "No venues found";
}

return result;‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos
AndrewSD
Occasional Contributor

Wow! Thank you very much! I will test this out and see how it works. Much appreciated!

XanderBakker
Esri Esteemed Contributor

Hi ButterfieldLECP ,

Let me know if you run into any problems. Happy to help.

0 Kudos
AndrewSD
Occasional Contributor

Hi Xander,

Again thank you!! So I did have an issues but it's probable me and I might have put the wrong values in. So repeat_venue is where the venue info is, org_venue and org_venue_address are the field names that have the name and address info. When I run a test it says, "Execution Error:Invalid Parameters for Count"  Not sure what I did wrong. 

Thank you!

// user clicked on organization, so that will be your $feature
// get related venue records, change name of relationship and fields according to your data
var fsvenues = FeatureSetByRelationshipName($feature, " repeat_venue ", ["org_venue ", " org_venue_address "], False);

// initialize result text and get count
var result = "";
var cnt = Count(fsvenues);

// check count and start creating result text
if (cnt > 0) {
   
// we have related records
    result
= cnt + " repeat_venue:";
   
// loop through venues
   
for (var venue in fsvenues) {
       
// add a line per venue and include name and address
        result
+= TextFormatting.NewLine + " - " + venue["org_venue "] + " (" + venue["org_venue_address "] + ")";
   
}
} else {
   
// we don't have related record, show that in the result
    result
= "No venues found";
}

return result;

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi ButterfieldLECP ,

I assume that this is caused by the additional space around the relationship name and the field names. Have a look at lines 3 and 16 where this is the case in the expression you shared.

Can you try this?

// user clicked on organization, so that will be your $feature
// get related venue records, change name of relationship and fields according to your data
var fsvenues = FeatureSetByRelationshipName($feature, "repeat_venue", ["org_venue", "org_venue_address"], False);

// initialize result text and get count
var result = "";
var cnt = Count(fsvenues);

// check count and start creating result text
if (cnt > 0) {
    // we have related records
    result = cnt + " repeat_venue:";
    // loop through venues
    for (var venue in fsvenues) {
        // add a line per venue and include name and address
        result += TextFormatting.NewLine + " - " + venue["org_venue"] + " (" + venue["org_venue_address"] + ")";
    }
} else {
    // we don't have related record, show that in the result
    result = "No venues found";
}

return result;
0 Kudos
AndrewSD
Occasional Contributor

Hi Xander,

It looks like I got the same error as above.

Andrew

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi ANDREW BUTTERFIELD ,

The second thing I would validate is the name of the relationship used on line 3. Since you had additional spaces in the name, I assume that you configured it manually and not using the interface. It is best to use the interface to avoid any typos in the process. 

So, go into the Arcade expression editor, click the ">" right to $feature:

Next, at the end of the list of attributes of the $feature you will find something called "Related records". Click the ">" right to it:

This will reveal the relationships that the layer has. Click on the "FeatureSetByRelationshipName" to insert the code into the expression. Edit the fields (watch out with additional spaces).

If it continues to produce errors, I would need to have access to the data to investigate a bit more. You could share the map and data to a new group and invite me "xbakker.spx" to this group to have access to the data and test the expression more efficiently.

0 Kudos
AndrewSD
Occasional Contributor

Xander,

I did not work so I am creating a group now. 

Thank you again!

Andrew

XanderBakker
Esri Esteemed Contributor

Hi ANDREW BUTTERFIELD ,

It seems that there is something strange going on in your data. I was expecting to find a relationship from the organizations info to the venue locations, but I only found one relationship towards Form_2. And when I try to use it, it returned an empty string as the relationship name:

Earlier you mentioned that the link between the two layers is established using the organization name, so I used that instead. have a look at the expression below:

// use organization name and venue name to link the information
var orgname = $feature["org_name"];

// access the venue featureset
var fsvenues = FeatureSetByName($map,"Venue Locations", ["org_venue", "org_venue_address", "org_venue_type"], False);

// create a SQL query to get the related venues
var sql = "org_name = @orgname";

// filter venues on org name / venue location
var venues = Filter(fsvenues, sql);

// count venues
var cnt = Count(venues);

// loop through venues and create result
var result = "";
if (cnt > 0) {
    // there are venues found, loop through venues
    result = cnt + " venues found:"
    for (var venue in venues) {
        // add venue information to the result
        result += TextFormatting.NewLine + TextFormatting.NewLine + venue["org_venue"];
        result += TextFormatting.NewLine + venue["org_venue_type"];
        result += TextFormatting.NewLine + venue["org_venue_address"];
    }
    
} else {
    // no venues found
    result = "no venues found...";
}

return result;

‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

The result will show like this:

Is this what you are after?