I am building a questionnaire tool where I use a loop layout to auto populate the question (and answer buttons). Currently, this is set up in a child module that is populating a parent module. I want to break these questions into their sections.
My object set to loop through has properties: questionnaireType, sectionName, QuestionText, IndexID. The loop filters based on questionnaireType selected to populate the QuestionText (sort by IndexID). I cannot see a way to group by in a simple loop layout - is this correct?
As a result, I am trying to do a loop in a loop where the âbabyâ module is the question loop as described above and then theres a child module above this that contains the section layout to loop through which finally populates the parent module. I am struggling with how to configure the middle layer to this so that the sections populate with the relevant questions. The parent module currently presents with each question in its own section loop.
The reason I am trying to approach it like this is because
a) the number of questions in a section differs section to section
b) the number of sections in a questionnaire differs as well
Weâre currently tracking feature requests internally to be able to:
loop over an aggregation of an object set
loop over an array variable
In your case you could populate an array variable with a unique values aggregation of the questionnaireType or sectionName property, depending on what you want to group by. Then in the child module you could filter the original object set on the array property being looped over. With that in mind I believe either of these features would allow you to do what you want here.
Since these are not available yet, for now you can construct an object set (perhaps function backed) that contains one object with each value you want to display a section for, which leads to a similar solution as looping over an array variable.
Could you advise on rough steps that I would need to add to this to set up the looping desired? Happy playing around with getting it working but conscious Iâm not clear on the specific steps to achieving the end goal.
We hope to have looping over an array out soon but no specific date right now, probably long enough out that itâs worth working around for now.
Youâll want your function to return an object set with one object with each property value you want to loop over. I donât have a specific example to share but youâll want to do something like groupBy the property youâre interested in, and then take the first object from each group. (perhaps something like a map of your grouped array to the first object in each group).
I parked this task but picking it up again now so keen to know if the features are in development or if you have any alternative way to group by within a loop layout?
It should be released shortly. Weâve developed looping over arrays and are doing some final testing before releasing broadly. You can expect an in product announcement when itâs available!
hey @evanj , have I missed a release for looping through object set aggregations? Is this leveraging the function-backed object set variable in workshop?
Hey @amhall, here is the release note: https://www.palantir.com/docs/foundry/release-notes/2025/?filters=app-building#May%2019,%202025-Enhancements
We should have support for looping over structs soon as well, but for now you could use an object set aggregation to populate an array variable, and then loop over that array.
Given the above, I am writing a function with the goal of it outputting an aggregated object set to loop through, reason being it is then dynamic to filtering and sorting based on an aggregated value. Below is the function I have written so far (fully anonymised)
Is defined promise correct and if so how to do the final output given I donât need it to modify the objects?
In this example I have created a placeholder object type that contains the âkeyâ with the plan to match on key and modify value properties. Is there a more suitable alternative where I can just output an aggregated object set without this placeholder?
@Function()
public async processDataREDACTED(
narrativeSet: ObjectSet<NarrativeData>,
quantitativeSet: ObjectSet<QuantitativeData>
): Promise<ObjectSet<ResultByCategory>> {
const [quantitative, narrative] = await Promise.all([
quantitativeSet.allAsync(),
narrativeSet.allAsync()
]);
// Constants
const QUANT_WEIGHT = 0.7;
const NARR_WEIGHT = 0.3;
const TARGET_YEAR = 2025;
const COMPARISON_YEAR = 2024;
// Single pass data structure
const categoryData = new Map<string, {
years: Map<number, { quant: QuantitativeData[], narr: NarrativeData[] }>,
entityPromise: string
}>();
// Group all data in one pass
this.groupDataByCategoryAndYear(quantitative, narrative, categoryData);
// Calculate REDACTED scores and build result
const pivotData: DataMatrix[] = [];
for (const [category, data] of categoryData) {
const currentYearData = data.years.get(TARGET_YEAR);
if (!currentYearData) continue;
const currentScore = this.calculateREDACTEDScore(
currentYearData.quant,
currentYearData.narr,
QUANT_WEIGHT,
NARR_WEIGHT
);
const trend = this.calculateTrend(
data.years.get(COMPARISON_YEAR),
currentYearData,
QUANT_WEIGHT,
NARR_WEIGHT
);
const narrScore = this.calculateREDACTEDScore(
currentYearData.narr
);
}
}