2 Replies Latest reply on Dec 13, 2013 7:43 AM by jmeinert

    How to create a cross-reference of paragraph number?


      In JavaScript, how can I create a cross-reference to a paragraph number located in a ParagraphStyle?  I have a script to create a questionnaire in InDesign which contains a series of numbered questions and I want to be able to create a cross-reference to denote which item the person filling out the form should skip to if certain conditions are met.


      For example:


      7. What is your gender?




      If "Male" skip to item 9.


      8. Have you ever been pregnant?




      9. What is your age?


      I want to be able to insert a cross-reference after the "Male" response linking to paragraph number in item 9.


      Any suggestions on how to do this would be greatly appreciated!




        • 1. Re: How to create a cross-reference of paragraph number?
          Peter Kahrel Adobe Community Professional & MVP



          To create a cross-reference, you need three things: a cross-reference format, the referenced paragraph, and the insertion point where the reference is to be inserted. You then create a source (a crossReferenceSource, using the xref format), a target (a paragraphDestination), and a hyperlink from the source to the target:


          // The cross-reference format (make sure it exists)
          crFormat = doc.crossReferenceFormats.item ('Paragraph Number');
          // The referenced paragraph, in your example, "9. What is your age?"
          targetParagraph = . . . // some paragraph
          // The place where the cross-reference should appear in the text,
          // in your example, after 'If "Male" skip to item '
          reference = . . . // some insertion point
          target = doc.paragraphDestinations.add (targetParagraph);
          xRef = doc.crossReferenceSources.add (reference, crFormat);
          doc.hyperlinks.add (xRef, target);



          • 2. Re: How to create a cross-reference of paragraph number?
            jmeinert Level 1

            Thanks Peter, that worked perfectly!!!