Related Records in Popup Does not Return All Values

536
2
Jump to solution
08-17-2023 09:59 AM
Labels (3)
ZachBodenner
MVP Regular Contributor

Hello, I am trying to compile some arcade code to view related records in the popup. The code seems to work fine. I used this article for reference and put it together in a pretty similar way. It's a great article and offers some good step-by-step as well as challenges to improve even more. Kudos to the author. So, the code I used is below:

// Write a script to return a value to show in the pop-up. 
// For example, get the average of 4 fields:
// Average($feature.SalesQ1, $feature.SalesQ2, $feature.SalesQ3, $feature.SalesQ4)
//set variables. First variable is the unique ID that is shared by the primary and related data. Second variable is calling the related forms as a FeatureSet
 
var codeGlobal = $feature.GlobalID;
var relatedForms = FeatureSetById($map, "189ffea4bbf-layer-175")
 
//create a filter statement where the maintenance form GUID = the Tree Inventory GlobalID
 
var filterStatement = "CompRel = @codeGlobal"

//a maintenance form equals the table run through the filter
 
var inspForm = Filter(relatedForms, filterStatement)
 
// Sort related features by oldest to newest
var relatedDataSorted = OrderBy(inspForm, 'InspDate ASC')
 
// Build the pop-up string by iterating through all related features. Add or subtract new lines in the popupString as needed from the related form.
var popupString = ''
for (var f in relatedDataSorted){
    
    popupString += Text(f.InspDate, 'MMMM DD Y') + TextFormatting.NewLine +
    
        "Inspection Type: " +
        DefaultValue(f.InspType, '') + TextFormatting.NewLine +
        
        "Inspection by: " +
        DefaultValue(f.InspBy, '') + TextFormatting.NewLine +
        
        "Findings: " +
        DefaultValue(f.Findings, '') + TextFormatting.NewLine +
        TextFormatting.NewLine

        "Investigation forwarded to: " +
        DefaultValue(f.FwdTo, 'Not forwarded') + TextFormatting.NewLine +
        TextFormatting.NewLine
 
        "Forward date: " +
        DefaultValue(text(f.FwdDate, 'MMMM DD Y'), '') + TextFormatting.NewLine +
        TextFormatting.NewLine
 
        "Owner action required: " +
        DefaultValue(f.OwnAction, 'None at this time') + TextFormatting.NewLine +
        TextFormatting.NewLine

        "Owner action deadline: " +
        DefaultValue(text(f.ActDate, 'MMMM DD Y'), 'None at this time') + TextFormatting.NewLine +
        TextFormatting.NewLine

        "Date letter sent: " +
        DefaultValue(text(f.LetterDate, 'MMMM DD Y'), 'Letter not yet sent') + TextFormatting.NewLine +
        TextFormatting.NewLine

        "Date of final inspection: " +
        DefaultValue(text(f.FinalDate, 'MMMM DD Y'), 'Final inspection not yet conducted') + TextFormatting.NewLine +
        TextFormatting.NewLine

        "In compliance?: " +
        DefaultValue(f.Comply, '') + TextFormatting.NewLine +
        TextFormatting.NewLine

        "Action taken by city: " +
        DefaultValue(f.CityAct, 'None') + TextFormatting.NewLine +
        TextFormatting.NewLine

        "Date forwarded to city attorney: " +
        DefaultValue(text(f.AttyDate, 'MMMM DD Y'), '') + TextFormatting.NewLine +
        TextFormatting.NewLine    
}
return popupString

//the default return is "Norelated forms"

 

My problem is, the popupString stops returning attribute values after the fourth attribute (in this case, "f.Findings". 

Here is a screenshot of the result:

ZachBodenner_0-1692291430091.png

 

I've tested this by re-ordering the attributes returned in the popupString, and when I do that, the reordering holds true but still stops at that fourth field. This tells me that's it's not likely that the code is just...stopping? truncating? at some kind of error in the code (no errors thrown when testing).

Any ideas?

0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor

You have an extra "TextFormatting.NewLine" in each of the lines from "Findings" onward

 

        "Inspection by: " +
        DefaultValue(f.InspBy, '') + TextFormatting.NewLine +
        
        "Findings: " +
        DefaultValue(f.Findings, '') + TextFormatting.NewLine +
        TextFormatting.NewLine // remove this

 

 Since they don't have a "+" after them, those lines are not added

View solution in original post

0 Kudos
2 Replies
KenBuja
MVP Esteemed Contributor

You have an extra "TextFormatting.NewLine" in each of the lines from "Findings" onward

 

        "Inspection by: " +
        DefaultValue(f.InspBy, '') + TextFormatting.NewLine +
        
        "Findings: " +
        DefaultValue(f.Findings, '') + TextFormatting.NewLine +
        TextFormatting.NewLine // remove this

 

 Since they don't have a "+" after them, those lines are not added

0 Kudos
ZachBodenner
MVP Regular Contributor

Wow it's kind of amazing how our eyes can pass over some things. Thanks or catching that!

0 Kudos