These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Array parameter does not accept a function that returns an array

dotnetwiz
Registered: Jun 8 2010
Posts: 57
Answered

I have a function called getFieldsArray() that returns an array of field names; something like
[ "field1", "field2" ]
I've taken pains to confirm that my function works as expected and returns an array.

I'm trying to figure out why the following code does not work:

var l_sDocXML = this.exportAsXFDFStr(
{
bAllFields : true,
aFields : getFieldsArray()
bNoPassword : true,
bAnnotations : false
});

If I assign the aFields parameter with a static array, everything works fine, but it won't work with a function that returns an array.

Any thoughts/insights?

My Product Information:
Acrobat Pro Extended 9.3.1, Windows
try67
Expert
Registered: Oct 30 2008
Posts: 2398
Might not be it, but I think there should be a comma after the call to getFieldsArray(). Also, are there any error messages?


PS - This is my 1,000 post here. Horray!

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

dotnetwiz
Registered: Jun 8 2010
Posts: 57
Congrats on your 1,000th post!

You're right about the comma--the code here is a bit simplified but captures the essential issue.

I'm not getting any error messages or syntax errors. The string return from the exportAsXFDFStr() call simply does not contain data from the fields.
try67
Expert
Registered: Oct 30 2008
Posts: 2398
Could you post the source code of getFieldsArray() ?

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

dotnetwiz
Registered: Jun 8 2010
Posts: 57
I hope this won't complicate matters too much. getFieldsArray() is an object method that returns an array of field names. I've tested it separately and I'm confident that it's not the source of the issue.. but I'm certainly not immune to coding bloopers.

getFieldsArray:
function()
{
var l_aFields = [];
for (var i = 0; i < this.fields.length; i++)
{
try
{
switch (this.fields[i].type)
{
case "checkbox":
case "combobox":
case "listbox":
case "radiobutton":
case "text":
l_aFields.push('"' + this.fields[i].name + '"');
break;
}
}
catch (error) {}
}
return l_aFields;
}

};
dotnetwiz
Registered: Jun 8 2010
Posts: 57
Not sure why, cos I had tried this earlier, but it's now working after I removed the quotes from my function:

case "text":
l_aFields.push(this.fields[i].name);
try67
Expert
Registered: Oct 30 2008
Posts: 2398
You were pushing the string with quotes around it (as a part of the text itself), which later caused a problem because the names of the fields do not contain quotes.

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

dotnetwiz
Registered: Jun 8 2010
Posts: 57
I get that, but I only did that after it wasn't working initially. I must have done something wrong somewhere else.. glad it's working now as would be expected.

Thanks for your assistance!