Skip to main content
Participating Frequently
November 22, 2013
Question

Multiple record data merge into paragraph styles-applies the wrong style

  • November 22, 2013
  • 1 reply
  • 45622 views

Hi, I've been working on this project for sometime and everytime I manage to get one part of the workflow to work another seems to break. My agency publishes catalogs in multiple formats: large-print, audio, braille, and HTML. I've been trying to redesing our work process so that the catalogs will be laid out from merged data out of comma-separated file. The data merges have worked fairly well in Word, but InDesign is a challenge. I'm merging multiple records on a page, like a mailing label. The paragraphs need to be formatted and I'm trying to apply a paragraph style to them. After much work, I think I've finally got the data merge to work correctly, but the wrong paragraph styles are applied. I'm going to apply a new master page to the data once the data is merge that uses the paragraph styles for text variable running headers and I need to build a table of contents based on the paragraph styles so I need this to work. Attached are some screenshots.

Master page set up for data merge with paragraph styles:

Here is the merged document with the wrong paragraph styles applied:

I have only a few weeks to get this process ironed out to keep to our rigorous production schedule. If anyone can help I would really appreciate it.

thanks,

Lina

1 reply

Peter Spier
Community Expert
Community Expert
November 22, 2013

Can't really tell from those screen shots what styles are applied to the placeholders....

LinaD36Author
Participating Frequently
November 22, 2013

Peter- All the styles on the screen have been applied.  The data has been merged onto 7 lines and each line has it's own paragraph style. But I think the problem is that some of the fields are empty and don't have data in them. The fields merged are below next to the paragraph style that they are supposed to be merged into:

<<GENRE>> (Genre)

<<SUBJECT_CODE>> (Subject Code)

<<TITLE_ARTICLE>><<TITLE>>(Title)

<<BN>> <<HRS>> hours<<MINS>> minutes (Time)

<<ROLE>> <<AFN>> <<ALN>> <<CONJ>> <<CFN>> <<CLN>> (author)

read by <<NFN>> <<NLN>> (narrator)

<<ANNOTATION>> (annotation)

The problem seems to occur because the Genre and Subject Code fields don't always have data in them and then somehow the Genre style is applied to the Title paragraph.

-Lina

Community Expert
December 5, 2013

Wow. I guess I hadn't clued into the idea that Uwe was work on another script for me. You guys are the best. I feel so fortunate to have so much help!

Lina


@7163524 – maybe you already did it manually…


But, here I'm back with a script, that is able to thread all the text frames of the datamerge together.

Run it AFTER you eliminated: the XML-tags, the <FEFF> special characters and the empty paragraphs.

 

A fair warning: It's not totally "watertight", but should work, if:

 

1. You want to thread all text frames on pages in a document by order of their creation; page by page!

 

Here I simply assume, that the datamerge is generating the text frames page by page from left to right, top to bottom.

So check the results!

 

2. There are NO text frames, that are already threaded together.

 

As a bonus I add a paragraph style to the document that is applied to a separator paragraph between the texts of the text frames. I named it "STORY-SEPARATOR". You could change its name if you want in line 10 of the script. Just make sure you'll leave  both quotation marks intact.

 

As another bonus you can undo the script's action in one go.

But as always: save the result to a different file name!

 

//StitchTextFramesAfterDatamerge_IN-CREATION-ORDER.jsx

//Uwe Laubender

 

//DESCRIPTION:Does NOT work, if some text frames are already stitched (threaded) together!!

 

/**

* @@@BUILDINFO@@@ StitchTextFramesAfterDatamerge_IN-CREATION-ORDER.jsx !Version! Thu Dec 05 2013 23:00:25 GMT+0100

*/

 

var storySeparatorParaStyleName = "STORY-SEPARATOR";

 

app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;

 

try{

app.doScript(_StitchTextFrames, ScriptLanguage.JAVASCRIPT, [], UndoModes.ENTIRE_SCRIPT, "Stitch text frames of document together: page by page.");

}catch(e){alert("Sorry, something went wrong:"+"\t"+e.message);exit(0)};

 

alert("DONE! New paragraph style named \""+storySeparatorParaStyleName+"\" added. Text frames on pages (not on the pasteboard) are threaded page by page in creation order!");

 

function _StitchTextFrames(){

 

var d=app.documents[0];

 

if(!d.paragraphStyles.itemByName(storySeparatorParaStyleName).isValid){

    d.paragraphStyles.add({name:storySeparatorParaStyleName});

    };

 

d.textFrames.everyItem().insertionPoints[0].contents = "\r\r";

d.textFrames.everyItem().paragraphs[1].appliedParagraphStyle = storySeparatorParaStyleName;

 

var firstTextFrameID = threadTextFramesInBuildingOrderPageByPage(app.documents[0]);

 

d.textFrames.itemByID(firstTextFrameID).characters[0].remove();

d.textFrames.itemByID(firstTextFrameID).characters[0].remove();

 

//FUNCTION

//Returns ID number of first built text frame by lowest number !!

 

function threadTextFramesInBuildingOrderPageByPage(myDoc){

   

    var d=myDoc;

    var myPages = d.pages;

    var IDArrayByPages = new Array();

    var n, m, currentTF, nextTF;

   

    for(n=0;n<myPages.length;n++){

        if(myPages.textFrames.length >0){

           

            IDArrayByPages = IDArrayByPages.concat(myPages.textFrames.everyItem().id.sort());

           

            };

        };

   

    //Stitch together:

    for(m=0;m<IDArrayByPages.length-1;m++){

       

        currentTF = d.textFrames.itemByID(IDArrayByPages);

        nextTF = d.textFrames.itemByID(IDArrayByPages[m+1]);

       

        currentTF.nextTextFrame = nextTF;

        };

   

    return IDArrayByPages[0];

    };

 

}; //END function _StitchTextFrames(){}

 

Uwe

 

NOTE TO MYSELF: Code is damaged because the thread was moved from the old InDesign Forum to the new one by the end of 2019.