This is what I have so far... It does not seems to be the best way if you have 25-50 fields to filter and collect.
//set the vars
var one = this.getField("A1");
var two = this.getField("A2");
var three = this.getField("A3");
var four = this.getField("A4");
var five = this.getField("Results");
//this function concatenates the fields values into one with a return as a separator.
function concatFields(field1,field2,field3,field4,fieldDest){
//ensure all vars are present
if(field1 && field2 && field3 && field4 && fieldDest){
var fieldVals = new Array();
if(field1.value!='' && field1.value!=null){
fieldVals.push(field1.userName);
}
if(field2.value!='' && field2.value!=null){
fieldVals.push(field2.userName);
}
if(field3.value!='' && field3.value!=null){
fieldVals.push(field3.userName);
}
if(field4.value!='' && field4.value!=null){
fieldVals.push(field4.userName);
}
fieldDestResult = fieldVals.join('\n');
//only populate the fieldDest if it's empty
//if(fieldDestResult.value!=''||fieldDestResult.value!=null){
fieldDest.value=fieldDestResult;
//}
}
}
concatFields(one,two,three,four,five);
Assuming you have 50 dropdowns named A1, A2, ...A50 and that each dropdown has three items (Yes, Maybe, No), you could do something like:
// Initialize object to hold response info
var oResponse = {
"Yes" : [],
"Maybe" : [],
"No" : []
};
var i, f;
// Loop through the fields (A1, A2, ...A50)
for (i = 1; i <= 50; i += 1) {
// Get a reference to the current field
f = getField("A" + i);
// Add tooltip text of current field to corresponding array in the response object
oResponse[f.valueAsString].push(f.userName);
}
// Generate the output string
var aOutput = [];
if (oResponse["Yes"].length > 0) aOutput.push("This is priority YES\r" + oResponse["Yes"].join("\r"));
if (oResponse["Maybe"].length > 0) aOutput.push("This is priority MAYBE\r" + oResponse["Maybe"].join("\r"));
if (oResponse["No"].length > 0) aOutput.push("This is priority NO\r" + oResponse["No"].join("\r"));
// Populate the results field
getField("Results").value = aOutput.join("\r\r");