Select to view content in your preferred language

No values are retrieved from a related table (for loop)

648
2
Jump to solution
06-16-2023 02:02 AM
Manniej
Emerging Contributor

Hello world, 

I could use your help with the following issue:  I'm trying to retrieve (string, text) values from a related table and present them in a PopUp (Enterprise 10.9.1, webmap). 

 I think the issue is a combination of line 2, 10  and 17. Since the code is working on a basic number field. Who can help me out?  (Thank you in advanced!) 

 

 

//Get information from the related table
var relatedtabel = FeatureSetByRelationshipName($feature,"XXXXXX.NAMETabel",["OL_FIRSTNAME","OL_LASTNAME","OL_DATE"]);
var cnt = Count(relatedtabel);

if (cnt > 0) {
console("Found value")
var num = 0;   //not sure if this is needed. 
var result = "";
var listvalues = [];
var info = (relatedtabel);

    for (var num=0; num < cnt; num++) {
        console("ascending number: [" + num + "]")
        console("total numbers found: [" + cnt + "]")
        var relatedinfo = "";
        
        relatedinfo = Text(info.OL_LASTNAME + "  |  " + Month(info.OL_DATE) + "-" + Year(info.OL_DATE)) + TextFormatting.NewLine;
        result += insert(listvalues,num,relatedinfo);
    }
    return Concatenate([listvalues]);  
}

// if there are no related data at all 

else {
console("no value found")
    var nodata = "";
    nodata = Text("Geen informatie");
    return nodata
}

 

 

 

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
MikeMillerGIS
Esri Frequent Contributor

Try this.  You do not want to call count on a FeatureSet, it is better to loop over it and handle when there is nothing to loop over

//Get information from the related table
var relatedtabel = FeatureSetByRelationshipName($feature,"XXXXXX.NAMETabel",["OL_FIRSTNAME","OL_LASTNAME","OL_DATE"]);

var related_results = [];
for (var row in relatedtabel){
    Push(related_results, row.OL_LASTNAME + "  |  " + Month(row.OL_DATE) + "-" + Year(row.OL_DATE));
}
if(Count(related_results) == 0){
    return "Geen informatie" 
}
return Concatenate(related_results,TextFormatting.NewLine);

View solution in original post

0 Kudos
2 Replies
MikeMillerGIS
Esri Frequent Contributor

Try this.  You do not want to call count on a FeatureSet, it is better to loop over it and handle when there is nothing to loop over

//Get information from the related table
var relatedtabel = FeatureSetByRelationshipName($feature,"XXXXXX.NAMETabel",["OL_FIRSTNAME","OL_LASTNAME","OL_DATE"]);

var related_results = [];
for (var row in relatedtabel){
    Push(related_results, row.OL_LASTNAME + "  |  " + Month(row.OL_DATE) + "-" + Year(row.OL_DATE));
}
if(Count(related_results) == 0){
    return "Geen informatie" 
}
return Concatenate(related_results,TextFormatting.NewLine);
0 Kudos
Manniej
Emerging Contributor

@MikeMillerGIS ,  that did the trick. Thank you so much.  

Even though I also realize that I still have a long way to go to master Arcade as a subject matter.

0 Kudos