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

access xfa field using JS in acrobat console?

JGarn23
Registered: Feb 17 2010
Posts: 35
Answered

Hi All,
How can I access a field written using live cycle designer when using the acrobat JS console?

I have a field in my xfa form at form1.main1.inputSg and want to access if from JS console.

I've tried
var f = this.getField("form1[0].main1[0].inputSg[0]|); but this doesn't work.

Thanks.

thomp
Expert
Registered: Feb 15 2006
Posts: 4411
You have to go throuh the XFA model, which, as it happens is a property of the document object.
like this:

var f = this.xfa.form.form1.main1.inputSg;

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

JGarn23
Registered: Feb 17 2010
Posts: 35
I can access my field fine in the console as requested. When I run the exact same code inside a trusted function script called from my form I get this in the console

this.xfa has no properties
24:XFA:form1[0]:main[0]:#subform[0]:createDef[0]:click

Any ideas?

Thanks.
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
The keyword "this" is a pointer to the current object. In many cases it is in fact a pointer to the document object, but no always, and not in this context. Since you are calling the trusted function from the LiveCycle form code you should pass in an object (from the LiveCycle form context) that relates to the object you want to affect. For example, you could pass in the field that you want to affect, "form1.main1.inputSg", or the document object pointer, which is in "event.target". So your function might look like this.
var myfunct = app.trustedFunction(function(oDoc){var myVar = oDoc.xfa.form.form1.main1.inputSg;...

Do not rely on the keyword "this" when the context is not known.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script