Skip to main content
jctremblay
Community Expert
Community Expert
August 29, 2016
Answered

Populating a field with results of others (sorting & adding custom text)

  • August 29, 2016
  • 2 replies
  • 2458 views

I have a PDF form with many popup fields asking «Yes», «Maybe» or «No». I need a way to collect all the answers, and sorting them, all the «Yes» first, than all the «Maybe», than all the «No». When I need after that sorting of the three answer, is put this into a «Results» field with the contain of the Tool tips for each popup and the ability to add some bold text, between the three sorted answers.

I was able to found some javascript in the forum here to collect the field data only. It does not seems to be easy to modify if you have many fields to collect/sort/extract.

Any help or direction to do this will be appreciated.

Thanks!

This topic has been closed for replies.
Correct answer George_Johnson

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");

2 replies

Inspiring
August 29, 2016

What do you mean by popup fields? Are they dropdowns (aka combo boxes), or something else?

How exactly do you want to sort? For example, first by field value (Yes, No, Maybe), then by field name or tooltip text, and/or something else? I would probably use a script the loop through the fields, get the field name, value, and tooltip text and load them into an array, as an array containing those three values. You can then use the built-in sort method of an array, probably with the help of a sorting function. You'd then output the sorted result to the Results field, which I'm assuming would be a multiline text field. If you provide an example of what you want the output to look like and an idea of the field names for the "popups", we can provide more guidance.

try67
Community Expert
Community Expert
August 29, 2016

That's not so simple to implement, especially the part about sorting them (based on what?) and adding bold text (that would require using Span objects the Rich Text Formatting option)...

jctremblay
Community Expert
Community Expert
August 29, 2016

It’s more filtering than sorting... I need to get all the «Yes» tool tips contain, than the «maybe», than the «no» (all in the order they appears in the form. I can live without the bolding of custom text.

And Georges, yes i’m talking about Combo box drop down list.

Inspiring
August 29, 2016

If you provide an example of what you want the output to look like and let us know what the field names of the dropdowns are, I'd be happy to provide more guidance.