Skip to main content
Participant
May 22, 2013
Answered

Data Merge not picking up all data fields

  • May 22, 2013
  • 1 reply
  • 1476 views

Hi,

I've been having a problem, posted here: http://forums.adobe.com/thread/1217090

Essentially, I have been using the script 'CSV2Tables' to prepopulate simple 2 column tables with information drawn from a CSV data source.

The tables consist of a title, and a block of information about that specific subject. Many of the blocks of information I am importing also contain data tags (<<DataTag>>)

The plan is to use CSV2Tables to populate the tables, then change data source and run a normal ID Data Merge to replace all of the <<tags>> within the tables with information from a second CSV data source.

The problem is, CSV2Tables is importing the data and prepopulating the tables just fine, but the data tags that are found within each body of text are being picked up as plain text (as Peter Spier has pointed out, they are being drawn from a plain text stream rather than being dragged from the Mail Merge panel) so when I try to run the ID Mail Merge, none of the fields are found within my document.

My question is - is there a method, or script available out there that can essentially do a Find/Change within a document, and replace plain text that appears like this <<PlainText>> with a Data Tag that is recognised by ID, which will allow me to run a Data Merge?

I have been told to check out some of the commercial plugins available out there, but registering and setting up demo's would require me to contact our IT provider for each, and that would be an exhaustive process.

Any help is much appreciated.

This topic has been closed for replies.
Correct answer Jump_Over

Hi,

As far as I know you need in fact a script to replace 'plain text' with dataMergeTextPlaceholders.

a small example;

Array.prototype.find = function (string) {

    for (var s = 0; s < this.length; s++)

        if (this == string) return s;

        return -1;

    }

var mFile, mDoc, mFields, mFieldsNames, mStory, mPlainTxt, mNameToCompare, mField_ID;

// edit this with proper .csv path

mFile = File(Folder.myDocuments + "/" + "Merge.csv");

mDoc = app.activeDocument;

mDoc.dataMergeProperties.selectDataSource(mFile);

mFields = mDoc.dataMergeProperties.dataMergeFields;

mFieldsNames = mFields.everyItem().fieldName;

// script assumes a text box with "plain texts" to replace is selected

mStory = app.selection[0].parentStory;

app.findGrepPreferences = null;

app.findGrepPreferences.findWhat = "<<.+?>>";

mPlainTxt = mStory.findGrep(true);

for (var k = 0; k < mPlainTxt.length; k++) {

    mNameToCompare = mPlainTxt.contents.slice(2,-2);

    mField_ID = mFieldsNames.find(mNameToCompare);

    if (mField_ID > -1) {

          mField = mFields[mField_ID];

        mDoc.dataMergeTextPlaceholders.add (

            mStory,

            mPlainTxt.insertionPoints[0],

            mField

            )

    mPlainTxt.remove();

     }

    }

At this point you could run a 'normal Data Merge'.

This should work for linked frames (one selected) or table inside selected frame

I hope it could be helpful for more complex task

rgds

Jarek

Message was edited by: Jump_Over ==> brackets added for last if statement

1 reply

SteveE91Author
Participant
May 22, 2013

Do I have everyone stumped?

Jump_Over
Jump_OverCorrect answer
Legend
May 22, 2013

Hi,

As far as I know you need in fact a script to replace 'plain text' with dataMergeTextPlaceholders.

a small example;

Array.prototype.find = function (string) {

    for (var s = 0; s < this.length; s++)

        if (this == string) return s;

        return -1;

    }

var mFile, mDoc, mFields, mFieldsNames, mStory, mPlainTxt, mNameToCompare, mField_ID;

// edit this with proper .csv path

mFile = File(Folder.myDocuments + "/" + "Merge.csv");

mDoc = app.activeDocument;

mDoc.dataMergeProperties.selectDataSource(mFile);

mFields = mDoc.dataMergeProperties.dataMergeFields;

mFieldsNames = mFields.everyItem().fieldName;

// script assumes a text box with "plain texts" to replace is selected

mStory = app.selection[0].parentStory;

app.findGrepPreferences = null;

app.findGrepPreferences.findWhat = "<<.+?>>";

mPlainTxt = mStory.findGrep(true);

for (var k = 0; k < mPlainTxt.length; k++) {

    mNameToCompare = mPlainTxt.contents.slice(2,-2);

    mField_ID = mFieldsNames.find(mNameToCompare);

    if (mField_ID > -1) {

          mField = mFields[mField_ID];

        mDoc.dataMergeTextPlaceholders.add (

            mStory,

            mPlainTxt.insertionPoints[0],

            mField

            )

    mPlainTxt.remove();

     }

    }

At this point you could run a 'normal Data Merge'.

This should work for linked frames (one selected) or table inside selected frame

I hope it could be helpful for more complex task

rgds

Jarek

Message was edited by: Jump_Over ==> brackets added for last if statement

SteveE91Author
Participant
May 23, 2013

Ran a test using this, I'm no ID expert so it took a bit of thinking.. however, it worked flawlessly so thank you!

Ideally now, if I can link all of the frames together (only a couple run onto a second page so they won't have any physical effect on each other) and do a rerun with this, hopefully the entire document will be done.

Thanks once again, cracking answer. I will be back to report.