Search code examples
javascriptimacros

Modify Files using imacros


I am using imacros for sending emails to subscribers and I need to know how to modify a datasource file in order to prevent duplication. I am using JS script to call iim script where the iim is provided with a file that contains email addresses.

I should send 200 Emails per click. I need to make a loop for the emails to be added to the -send to section- but I recently discovered that I can't make a loop inside iim script so i figure out that the best way is to delete the read record and I don't know how.


Solution

  • Let your original file 'test_edit.txt' be as follow:

    "1
    2
    3
    4
    5"
    

    Play the following macro:

    SET file "test_edit.txt"
    SET folder {{!FOLDER_DATASOURCE}}
    SET !DATASOURCE {{file}}
    SET newCol EVAL("var newCol = '{{!COL1}}'.split(/\s+/); newCol.shift(); newCol;")
    SET !EXTRACT EVAL("'{{newCol}}'.replace(/,/g, '\\n');")
    FILEDELETE NAME={{folder}}\{{file}}
    SAVEAS TYPE=EXTRACT FOLDER={{folder}} FILE={{file}}
    

    Then you've got a modified file that looks like this:

    "2
    3
    4
    5"