1 Reply Latest reply on Jun 22, 2016 4:38 AM by Bernd Alheit

    Hierarchy field names and spawned page prefix

    alexh90310518 Level 1

      Hello,

      I'm trying to come up with a way of incrementing a text field that displays a page number, eg; 1 of 2

      This has to work with spawned pages from a hidden template and so there is no set number of pages.

       

      I have managed to get the initial pages to increment fine however the spawned pages are proving to be a little bit more of a challenge.

      The layout of the text boxes is as such;

      "Page#Pref" this is the text box that holds the number 1 in "1 of 2" therefore I have called it Page#Pref.

      "Suf.Page#Suf" this is the text box that holds the number 2 in "1 of 2" and so I have called it Page#Suf. I have also given this text box a hierarcial field name as multiple of these will need to be changed as more of the pages are spawned.

      Okay so this is my script at the moment for incrementing the fields;

      Mouse Up>Run a JavaScript

      var pgPrefix1 = this.getField("Page#Pref1");
      pgPrefix1.value++;//here I increment the pref text field on the hidden template
      pgGlzMain.spawn({nPage: pageNum + 1, bRename: true, bOverlay: false});//spawn a copy of the hidden template
      pageNum = this.pageNum+1;
      var HPref = "Suf.";//setting the prefix of the hierarchical field names 
      for (var i = 0; i < this.numFields; i++) {
           if (this.getNthFieldName(i).indexOf(HPref) == 0) {
                if (this.getField(this.getNthFieldName(i)).type == "text") {
                     this.getField(this.getNthFieldName(i)).value++;/*loop through all the text fields 
                                                                       and increment those with "Suf."*/
                }
           }
      }
      

      This works fine with the initial page that the button is on, that becomes page 1 of 2, the hidden template becomes 2 of 2 (I set it visible it to check this)

      However the spawned page does not increment correctly, it becomes page 2 of 1. That means the Page#Pref incremented correctly as I expected however the Suf.Page#Suf did not.

      I am wondering if this is to do with the fact that due to how page spawning works the field name has changed to "p1.pgGlzMan.Suf.Page#Suf" however I can't be certain that this is the problem.

      Any suggestions?

      Any help is much appreciated.

      Thank you in advance