Hi,
So check this modification (replace for...loop)
var countFrames= 0, currLabel, capPerPage; for (i=0; i<myDocument.pages.length; i++){ // TOTAL NUMBER OF PAGES IN DOCUMENT for(x = 0; x < myDocument.pages[i].textFrames.length; x++){ //COUNT TOTAL TEXT FRAMES PER PAGE currLabel = myDocument.pages[i].textFrames[x].label; // current textFrame label if(myDocument.pages[i].textFrames[x].label.search("caption") < 0) continue; else{ capPerPage = Number(currLabel.match(/\d+/)[0]); // current label number value var captionString = 'caption'+(countFrames + capPerPage); // recalculated to find proper placeholder var myTextFrame = myDocument.pages[i].textFrames[x]; var myStory = myTextFrame.parentStory; var myStoryOffset = myTextFrame.parentStory.insertionPoints[-1]; var myNamePlaceHolder = myDocument.dataMergeTextPlaceholders.add(myStory, myStoryOffset, get_field(captionString, myDocument)); // ADD DATA MERGE TEXT HOLDER TO TEXT FRAME } } countFrames += x; // INCREASE COUNT TO ADD frames found on previous pages}
Notice countFrames starts from 0.
Jarek