Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

setFocus pathing for PDF Linking

Avatar

Level 1

I’m in over my head.

As this would be my first experience with Javascript (aside from taking
the Developing Forms class), I’m in unfamiliar territory.  Please assume
a minimum level of Javascript experience for any suggested course of
action and thanks in advance for any help.

My process is (or will be, hopefully) the automatic transformation of an
input XML file into a potentially lengthy PDF made up of 3 sections: the
Body, Appendix A, and Appendix B.  Appendices A and B will be dynamically
constructed from content in the XML input.  I suspect I will end up
composing each section independently and then use Assembler to put the
three composed sections together into a single PDF.

The Body is made up of many small sections, each of which can contain
(among other things) one or more tables.  The instructions from the user
are to take any tables with more than 25 rows and move them from the Body
to Appendix A.  For these instances, I’ll need to introduce a link within
the appropriate section to the table in Appendix A.

I can imagine introducing a repeating tableLink element within each section
for the table links to Appendix A. I’d use XSLT to scan the XML and ferret
out the big tables, putting the table index into my new tableLink element. 
In the form, the Click event for the tableLink button would have the
setFocus method, which would need to pick up the value of the tableLink
element to build the path to the appropriate repeating table instance in
Appendix A.

Ugh.

I decided to begin by experimenting with something a little less variable. 
I introduced a button within the form fragment for the Body section that
would link to a specified section instance. I then used the section
fragment within a higher-level form as a repeating subform. I associated
a setFocus method with the new button, trying many different pathing
variations (like xfa.form.ItemName.MRCGroup.#MRC[4] – where MRC is the
name of the repeating section) to get a jump in the PDF Preview from the
first to the 5th instance of the MRC, but none worked.  It doesn’t throw
any error, but neither does it jump down a couple pages, as expected.

Can somebody help me with constructing setFocus pathing to a specific
instance of a repeating structure within a larger form?

Taking the question to the next level, how will I construct the setFocus
pathing from the Body to Appendix A or Appendix B once I Assemble the
three separate sections into a single PDF? 

Might it looks something like, “xfa.form.AppxA.#Table[$variable]”
(where $variable is the value of the tableLink element)?  Or would the
path be different at the top as the three parts of my document will have
been combined into new single PDF by Assembler?

Thanks in advance.
Dan Bono

1 Accepted Solution

Avatar

Correct answer by
Former Community Member

There is nothing wrong with your logic ....the issue is that the cursor cannot be positioned in a field that dos not exist yet. From Acrobat's perspective the field does not exist until the script that created it ends. So If you are trying to position the cursor in teh same script that doea the addInstance then it will not work (because Acrobat has not registered the objects yet). You can use an AcroForm command to execute a command at some time in the future. I have used this technique to accomplish what you want. Here is the command:

var

setField = app.setTimeOut("this.getField('form1[0].Page3[0].TextField4[0]').setFocus();", 1000);

Where 1000 is the time to wait before executing the command in milliseconds.

Note the reference to the object in its full form.

Paul

View solution in original post

4 Replies

Avatar

Correct answer by
Former Community Member

There is nothing wrong with your logic ....the issue is that the cursor cannot be positioned in a field that dos not exist yet. From Acrobat's perspective the field does not exist until the script that created it ends. So If you are trying to position the cursor in teh same script that doea the addInstance then it will not work (because Acrobat has not registered the objects yet). You can use an AcroForm command to execute a command at some time in the future. I have used this technique to accomplish what you want. Here is the command:

var

setField = app.setTimeOut("this.getField('form1[0].Page3[0].TextField4[0]').setFocus();", 1000);

Where 1000 is the time to wait before executing the command in milliseconds.

Note the reference to the object in its full form.

Paul

Avatar

Level 1

Paul,

Thanks for the answer.  It works. I don't understand it, but I welcome it.

Now that I have the mechanism to link withing the PDF, the next-level

question is all that remains.

Linking within a given form is no problem since we can know the path

to the object.  In my case, I wil be merging three separate documents

into a single PDF and the link will have to go from the Body to either

Appendix A or Appendix B.

I assume there will be a new root element for the combined PDF.  I

also assume I'll need that element name in the setFocus pathing.

Is there some way to know what the new document root element will

be for the merged PDFs?

Thanks again for your help.

Dan Bono

Avatar

Former Community Member

If there are no fields on the merged documents then there is nothing to link to. Do they have fields?

Paul

The following has evaluated to null or missing: ==> liqladmin("SELECT id, value FROM metrics WHERE id = 'net_accepted_solutions' and user.id = '${acceptedAnswer.author.id}'").data.items [in template "analytics-container" at line 83, column 41] ---- Tip: It's the step after the last dot that caused this error, not those before it. ---- Tip: If the failing expression is known to be legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)?? ---- ---- FTL stack trace ("~" means nesting-related): - Failed at: #assign answerAuthorNetSolutions = li... [in template "analytics-container" at line 83, column 5] ----