I have a table with records from a repeat question in survey123. I am trying to loop through and return all associated records and display in a list.
Table:
My attempt to use advanced formatting to get this to work:
// Initialize empty strings to store results
var problemResults = "";
var solutionResults = "";
// Loop through capability_target_problem array
for (var i in $datapoint.capability_target_problem) {
problemResults += $datapoint.capability_target_problem[i] + ", ";
}
// Loop through capability_target_solution array
for (var j in $datapoint.capability_target_solution) {
solutionResults += $datapoint.capability_target_solution[j] + ", ";
}
// Remove the trailing comma and space from the result strings
problemResults = Trim(Left(problemResults, Count(problemResults) - 2));
solutionResults = Trim(Left(solutionResults, Count(solutionResults) - 2));
// Combine the results into a single string or return as separate values
var combinedResults = "Problems: " + problemResults + " | Solutions: " + solutionResults;
// Return the combined results
return combinedResults;
return {
textColor: '',
backgroundColor: '',
separatorColor:'',
selectionColor: '',
selectionTextColor: '',
attributes: {
combinedResults
}
}
Line item:
Results = empty list:
My goal is to get all 4 problem and solutions shown above records to display
Solved! Go to Solution.
Based on the fields and the filter, I'm confused how it's only giving you one. It should be as simple as setting up the filter.
That said, when you're configuring a widget, you should get to preview the widget in its unfiltered state. The fact that you're only seeing one even on the configuration screen is strange. Is it as simple as the "maximum features" setting?
Or perhaps there's a filter on the widget?
Advanced Formatting evaluates per-feature. It won't really have a way of accessing related data or anything. You say "loop through array", but unless the field itself has an array in it (not impossible, but I've never seen anyone actually do it), there won't be anything to loop through.
Couldn't you just reference the fields directly in the item template?
@jcarlson thanks for the feedback, Josh! I was probably going at this the wrong way and didn't explain my workflow in enough detail. I have a table populated within a dashboard with records from a Survey123 form. In that form, there is a repeat question creating a related table with the problem/solution responses I would like to display in the list. Within the table, I have a filter established to populate the list displaying all the problems/solutions (could be 0-30) associated with that selected record.
Table:
Filter:
Current list (returns only first problem/solution)
Current list configuration:
Repeat table:
My desired outcome would be to get all 4 of the related Problems/Solutions to display in the list from the selected record in the table
Based on the fields and the filter, I'm confused how it's only giving you one. It should be as simple as setting up the filter.
That said, when you're configuring a widget, you should get to preview the widget in its unfiltered state. The fact that you're only seeing one even on the configuration screen is strange. Is it as simple as the "maximum features" setting?
Or perhaps there's a filter on the widget?
@jcarlson that was it! I had Maximum features displayed set to 1. I bumped to 100 and they all display. I should have caught that. Thanks again for your help with this, it is always appreciated!
I am actually glad I saw this as I have a similar situation I am trying to work through (here is my post, but I will do a TLDR here, too).
Basically, I want to do a loop of any multiple choice selected answer from a survey123. The issue is that they get submitted like this:
Which A) I need spaces and B) makes it difficult to create a list. Would using some similar syntax to what you have above (for var x +=) work for something like this? I am still learning more advanced arcade expressions so looping and adding to a list is something new for me!