Hi!
To answer you prior question:
- is there a script where I can command: ´´show values from all boxes in range Text1A - Text37C with data together, separate it by commas and skip empty fields ´´ or is it too complicated?
Is not that complicated.
What you're referring to is about how the cells are organized in a range in MS Excel for calculation.
In Acrobat JavaScript this is done in a similar fashion using an array.
You use the getArray method to get the child fields that belong to a parent field with the same prefixed name, and of course, together with the aid of an "IF or ELSE" condition.
See my example below which I took from the JavaScript API Reference, Field methods, page 416:
var f = getField("Text3");
if ( f !== "" ) {
var a = f.getArray();
var v = "";
for (j =0 ; j < a.length ; j++) v += (a[ j ].value+" ")
event.value = v;
}
else event.value ="";
In the example above you can use something similar but the complicated part in your case would be the time consuming task of renaming all of thos etext fields that you have and also changing their names on each line of code for it to work.
Now that I provided you with the code it should be a lot easier if you just delete all of those text fields and recreate them using the appropriate naming convention instead of manually changing them one by one.
Trust me, I just learned this the hard way recently. And the getArray method won't work if you have different field names like the way you have it now:
var s1 = "this.getField("Text3A").valueAsString".
All of your fields that are named with Text3 should be prefixed by adding a period like this:
Text3.A
So Text3 is considered the parent field name in this context, and every other field like Text3.A, Text3.B, Text3.C and such, would be referred to and treated as the children fields.
The array loop example above just focuses on the children fields that have a value and it will add up all of these values together and ignore the empty or NULL ones during the loop.
Also as you can see in that examlpe, I added a spcae to separate those valued from one another. However, I'm stuck right now with figuring out how to separate them with a coma. I am not that knowledgeable in javascript yet. So this other part involves additional scripting that I am not too familiarized with.
Maybe converting the array to a string and joining the array with a coma can be accomplished using these other examples:
https://stackoverflow.com/questions/39771131/how-to-convert-array-into-comma-separated-string-in-javascript
I was asked to help out, so here's my method of doing something like that, without having to rename any fields:
var values = [];
for (var i=1; i<=37; i++) {
for (var j="A".charCodeAt(0); j<="C".charCodeAt(0); j++) {
var fname = "Text"+i+String.fromCharCode(j);
var f = this.getField(fname);
if (f==null) {
console.println("Error! Can't find the field: " + fname);
continue;
}
if (f.valueAsString!="") values.push(f.valueAsString);
}
}
event.value = values.join(", ");