1 Reply Latest reply on Jan 7, 2011 2:01 PM by caseyctg

    Setting snippet according to what csv value is imported

    caseyctg

      Hey guys, I have a datamerge, merging from a CSV. The CSV comes from a google doc form submission. I've then downloaded the .csv file. I've been successful in merging the data. my question is how to format the data after it's merged, or before its placed into its text box.

       

      Basically, I have 15 options for a user to choose. So lets say the google form field options would be (option 1, option 2, option 3, etc.)

       

      What I want to do is import a snippet according to which option they select.

       

      so when the user selects "option 2" the script would compare against option 2 and would pull in Snippet2.idms.

       

      I am wanting this to use javascript.

       

       

      //DataMerge.jsx

      //An InDesign CS3 JavaScript

      //

      //Performs a data merge given an InDesign template

      //file and a data file.


      main();

      function main()

      {


      //You'll have to fill in valid files names on your system

      //for the data file and the InDesign template file.


      var myDocument = app.open(File("/Automation/Auto.indd"));


      var myDataSource = File("/Automation/file.csv");


      myDocument.dataMergeProperties.selectDataSource(myDataSource);


      myDocument.dataMergeProperties.mergeRecords();


      myDocument=myDocument.save("/Automation/datamerge3.indd");


      myDocument.close();

      }

       

       

      is my start. Can anyone send me in the right direction???

        • 1. Re: Setting snippet according to what csv value is imported
          caseyctg Level 1

          I figured out that it was better to do this after the merge instead of doing it before. Meaning, I save the document, close it, and then reopen it. Then rather than checking against data merge fields, I check against the text box itself and use a replace method.

           

          //DataMerge.jsx

          //An InDesign CS3 JavaScript

          //

          //Performs a data merge given an InDesign template

          //file and a data file.

           

          main();

           

          function main()

          {

           

          //You'll have to fill in valid files names on your system

          //for the data file and the InDesign template file.

          var myDocument = app.open(File("Automation/Auto.indd"));

           

          var myDataSource = File("Automation/Test.csv");

           

          myDocument.dataMergeProperties.selectDataSource(myDataSource);

           

          myDocument.dataMergeProperties.mergeRecords();

           

          //myDocument=myDocument.save(File("Automation/datamerge3.indd"));

           

          //myDocument.save(File("Automation/datamerge3.indd"));

           

          app.activeDocument.save(File("Automation/datamerge3.indd"));

           

          myDocument.close(SaveOptions.no);

           

          FormPage1()

          }

           

          function FormPage1()

          {

           

               var newDoc = app.open(File("Automation/datamerge3.indd"));

           

          //I set my text box with a script label to find the text box, then I compare the contents and replace it if it matches.

          if(newDoc.pages.item(0).pageItems.item("Field1ScriptLabel").contents=="Option1")

          {

               //This changes the field's text content

               newDoc.pages.item(0).pageItems.item("Field1ScriptLabel").contents = "Option 1 Text";

                  //This places the snippet

               newDoc.pages.item(0).place(File("Automation/Snippet.idms"), [328, 78], undefined, false, true)[0];

          }

           

          if(newDoc.pages.item(0).pageItems.item("Logo").contents.substring(0,7)=="Option4")

          {

               newDoc.pages.item(0).pageItems.item("Logo").contents = "oh yeah, Option 4 loaded and changed";

          }

           

           

          }//END FormPage1