Use Arcade Expression to get the values of a related table to use later in a Chart within Pop-ups

3790
4
Jump to solution
06-22-2020 04:42 PM
AndresEcheverri
New Contributor III

Hi All

I was wondering if someone could help me with this. I am trying to use a similar approach that have been suggested by Xander Bakker to use the‌ Filter function to get an array to use later in a chart. I have a hosted Feature Layer (Points) with the location of some wells. And I have an additional Table which has the "well" field (string field) in common with the hosted feature layer. From this table I was looking to pull out a couple of fields (oil production and date) to produce a Chart and add this chart to the Pop-up. The code in Arcade that I have is this one (from one previous post):

// first read out the well field of the Well layer
var well_name = $feature.well;
// access the table Monthly Production 
var tbl = FeatureSetByName($map,"FL_SA_PEPS_DATA - MonthlyProduction");
// create a sql expression to query on well
var sql = "well = '" + well_name + "'";
// filter the table using the sql expression
var related_data = Filter(tbl, sql);
// count the resulting records
var cnt = Count(related_data);

// initiate a variable to hold the result
var result = "Related records: " + cnt;;

// check if there are related records found for the current ID
if (cnt > 0) {
    // loop through related records
    for (var row in related_data) {
        // read some data and create the line you want
        
        //add the line to the result
       result += TextFormatting.NewLine + row.oil__m3_;
    }
}


// return the result
return result;‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

With that code, I am able to get the list of dates or oil production and display those in the pop-up as text. Is it possible to use this as an array or sort of field to use them for the chart creation?. I can't see the result as an input for the chart.  I tried with this variant from other post: 

// initiate a variable to hold the result
var result = 0;

// check if there are related records found for the current ID
if (cnt > 0) {
    // loop through related records
    for (var row in related_data) {
       //add the line to the result
       result += row.oil__m3_;
    }
}

In this case, I got a single number, which then I can see as an input to create the chart, but is only a single number and not an array or table. Not sure what approach should I do?. Is something possible to do?. I am working in Portal for ArcGIS  10.7. Any help would be much appreciated.

Thanks,

Andres

0 Kudos
1 Solution

Accepted Solutions
XanderBakker
Esri Esteemed Contributor

Hi Andres Echeverri , 

I just did some testing and although Arcade can return an array or a featureset, to create a diagram in the pop-up you will need to return a number. However, a single number does not make much sense for creating a diagram. When I returned a featureset or an array it did not recognize the result and it could not be used to create a diagram.

View solution in original post

4 Replies
XanderBakker
Esri Esteemed Contributor

Hi Andres Echeverri , 

I just did some testing and although Arcade can return an array or a featureset, to create a diagram in the pop-up you will need to return a number. However, a single number does not make much sense for creating a diagram. When I returned a featureset or an array it did not recognize the result and it could not be used to create a diagram.

AndresEcheverri
New Contributor III

Thanks for you answer Xander Bakker‌. Would be nice to have that functionality in the future!!.

XanderBakker
Esri Esteemed Contributor

Hi andres.echeverri@beachenergy.com.au ,

I would indeed be nice and I voted your idea up...

0 Kudos
Sean_Carroll_USACE
New Contributor

XanderBakker, 

I wasn't sure how to contact you, but I see your names all over Arcade related posts, so I am hoping you can help. I have a script where all I am trying to do is pass a value through from a related table to a related point feature. I just want the pop-up to show the parentobjectID from the related table. I have written the call like this:

var portal = FeatureSetByName($map,"service_01dd723bd96e4f19bd214978066544dd - report_photos")

var ParentID = $feature["globalid_1614018009466"]

if
(ParentID == portal) {
return portal;
} else {
return portal;
}

It returns the results shown in the attached image.

It seems like what I want is simple, the pop-up in the parent record to display a custom attribute that is the exact value shown in the child record as the attribute "parentglobalid". I am hoping it is simple and I am just messing up the code? Thanks!

 

0 Kudos