Thanks for the response.
This is a follow-up to this post Re: Cascading Multi-selects: Only showing unique c... - Esri Community
I can't post my survey here, but my real questions are looking at how historic land divisions overlay current tax parcels. In order to filter correctly, I did a spatial join on them, with an end result of 144k tax parcels that get filtered down by what choices are selected elsewhere. That being said, depending on the choices selected earlier in the survey, there can still be as many as 200 available to select at once.
I built this script to get around having to write out 200 increasingly more complex if statements. These if()s are the only way I could get the duplicates created by the spatial join to only show up once, but the problem is that it's tied to how many choices are selected.
I guess the alternative to just have javascript create the choicelist manually, but that's going to be a lot harder to write than this script was. I ended up modifying the script I wrote to generate the nasty if() statements so I don't have to. I'm just going to plug in 250 and then paste the output into the filter column. See below for the code.
It's definitely not as elegant as what I originally wanted to do, but the output functions as intended, so I can't complain too much.
I think this would be a good functionality to have in S123, though: being able to take formulas written as values in another question, if not a script output, and use them as filter rules, instead of just filter objects.
Like you say, the choice-filter reads the formula as a string and searches for the string.
The code to mass-generate the if() statement. Plug it into any javascript playground and it'll get all those if() statements.
function choicenum(N) {
var index_range = [];
//Create an index range based on the count-selected in the question.
for (var i = 1; i <= N; i++) {
index_range.push(i);
}
// Create your filter statements
var filterstr = []
for (var y in index_range) {
var midstr = []
midstr.push("if(count-selected(${Animal})=" + (Number(y)+1) + ", ");
// Create a sub-index for the second clause of the if()
var subindex= []
for (var f = 0; f <= y; f++) {
subindex.push(f);
midstr.push("contains(Animal, selected-at(${Animal}, '" + f + "' )) or ")
}
// Concatenates into a string, joined by a dummy character
var split_char= "?"
midstr = midstr.join(split_char);
// splits along the dummy character and stitches back together
midstr= midstr.split(split_char).join('');
// Removes the last "or" from the string
midstr = midstr.substring(0, midstr.length -4)
filterstr.push(midstr);
}
filterstr = filterstr + ", \"\"" +")".repeat(N)
return filterstr
}
//Outcome for N=2
//if(count-selected(${Animal})=1, contains(Animal, selected-at(${Animal}, '0' )),
//if(count-selected(${Animal})=2, contains(Animal, selected-at(${Animal}, '0' ))
//or contains(Animal, selected-at(${Animal}, '1' )), ""))
console.log(choicenum(2))