1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How to loop macros with Javascript?

Discussion in 'Other Scripting Languages' started by hillz, Mar 2, 2014.

  1. hillz

    hillz Registered Member

    Joined:
    Aug 14, 2011
    Messages:
    54
    Likes Received:
    3
    I'm sorry for not being clear last time mate, can you run this code in your computer?

    1. Datasource.iim
    Code:
    VERSION BUILD=8240212 RECORDER=FX
    TAB T=1
    'SET !REPLAYSPEED SLOW
    SET !ERRORIGNORE YES
    SET !TIMEOUT_STEP 0
    SET !DATASOURCE test.csv
    SET !DATASOURCE_COLUMNS 4
    SET !DATASOURCE_LINE {{!LOOP}} 
    SET !LOOP {{myLoop}}
    SET !EXTRACT_TEST_POPUP NO
    SET !TIMEOUT 60
    
    
    URL GOTO=galihpa.tk
    TAG POS=1 TYPE=INPUT:TEXT FORM=ID:usrform ATTR=NAME:usrname CONTENT={{!COL1}}
    TAG POS=2 TYPE=INPUT:TEXT FORM=ID:usrform ATTR=NAME:usrname CONTENT={{!COL2}}
    TAG POS=3 TYPE=INPUT:TEXT FORM=ID:usrform ATTR=NAME:usrname CONTENT={{!COL3}}
    
    
    TAG POS=1 TYPE=INPUT:TEXT FORM=ID:usrform ATTR=VALUE:* EXTRACT=TXT
    TAG POS=2 TYPE=INPUT:TEXT FORM=ID:usrform ATTR=VALUE:* EXTRACT=TXT
    TAG POS=3 TYPE=INPUT:TEXT FORM=ID:usrform ATTR=VALUE:* EXTRACT=TXT
    2. Job.iim
    Code:
    URL GOTO=galihpa.tk/test
    TAG POS=1 TYPE=INPUT:TEXT FORM=ID:usrform ATTR=NAME:usrname CONTENT={{myData1}}
    TAG POS=2 TYPE=INPUT:TEXT FORM=ID:usrform ATTR=NAME:usrname CONTENT={{myData2}}
    TAG POS=3 TYPE=INPUT:TEXT FORM=ID:usrform ATTR=NAME:usrname CONTENT={{myData3}}
    WAIT SECONDS=5
    3. test.js
    Code:
    var i;
    var data1;
    var data2;
    var data3;
    var data4;
    var data5;
    var data6;
    var data7;
    
    
    for (i = 1; i < 5; i++)
        {
            function myFunction()
                {
                    iimSet ("myLoop",i);
                    iimPlay ("Datasource.iim");
                    
                    data1 = iimGetLastExtract(1);
                    data2 = iimGetLastExtract(2);
                    data3 = iimGetLastExtract(3);
                    
                    iimSet ("myData1", data1);
                    iimSet ("myData2", data2);
                    iimSet ("myData3", data3);
                    
                    iimPlay ("Job.iim");
                }
            myFunction()
        }
    And here's the test.csv file

    Please run that test.js file, you'll notice that on the first-last loop, the extracted data is always like this:
    1. address1
    2. zip1
    3. city1

    What I want is like this:
    First loop:
    1. address1
    2. zip1
    3. city1

    Second loop:
    1. address2
    2. zip2
    3. city2

    Third Loop:
    1. address3
    2. zip3
    3. city3

    I hope this is easier to understand. Please tell me where I went wrong with that script.
    Thanks.
     
    Last edited: Mar 3, 2014
  2. E=MC²

    E=MC² Junior Member

    Joined:
    Apr 12, 2013
    Messages:
    176
    Likes Received:
    183
    I can help you but I need to see the entire code.
    Basically you need to create a javascript loop and use iimset to set variables that will be used instead of the imacros loop.
     
  3. hillz

    hillz Registered Member

    Joined:
    Aug 14, 2011
    Messages:
    54
    Likes Received:
    3
    oops repost sorry
     

    Attached Files:

    Last edited: Mar 2, 2014
  4. hillz

    hillz Registered Member

    Joined:
    Aug 14, 2011
    Messages:
    54
    Likes Received:
    3
    Here's the code:

    Scripts:
    1. login.iim (private sorry, but this has nothing to do with the question)
    2. PasteData.iim

    Code:
    VERSION BUILD=8810214 RECORDER=FX
    TAB T=1
    'SET !REPLAYSPEED MEDIUM
    SET !ERRORIGNORE YES
    SET !TIMEOUT_STEP 0
    SET !DATASOURCE test.csv
    SET !DATASOURCE_COLUMNS 5
    SET !LOOP {{myloop}}
    SET !DATASOURCE_LINE {{!LOOP}}
    SET !EXTRACT_TEST_POPUP NO
    SET !TIMEOUT 60
    
    TAG POS=1 TYPE=SPAN ATTR=TXT:Edit<SP>address
    TAG POS=1 TYPE=INPUT:TEXT FORM=ACTION:account_address_edit2.php ATTR=NAME:Address_1 CONTENT={{!COL1}}
    TAG POS=1 TYPE=INPUT:TEXT FORM=ACTION:account_address_edit2.php ATTR=NAME:Zip CONTENT={{!COL2}}
    TAG POS=1 TYPE=INPUT:TEXT FORM=ACTION:account_address_edit2.php ATTR=NAME:City CONTENT={{!COL3}}
    TAG POS=1 TYPE=INPUT:TEXT FORM=ACTION:account_address_edit2.php ATTR=NAME:State CONTENT={{!COL4}}
    WAIT SECONDS=5
    
    3. AnotherPasteData.iim

    Code:
    VERSION BUILD=8810214 RECORDER=FX
    TAB T=1
    'SET !REPLAYSPEED MEDIUM
    SET !ERRORIGNORE YES
    SET !TIMEOUT_STEP 0
    SET !DATASOURCE test.csv
    SET !DATASOURCE_COLUMNS 5
    SET !LOOP {{myloop}}
    SET !DATASOURCE_LINE {{!LOOP}}
    SET !EXTRACT_TEST_POPUP NO
    SET !TIMEOUT 60
    
    TAG POS=1 TYPE=SPAN ATTR=TXT:Edit<SP>address
    TAG POS=1 TYPE=INPUT:TEXT FORM=ACTION:account_address_edit2.php ATTR=NAME:Lingkungan_1 CONTENT={{!COL1}}
    TAG POS=1 TYPE=INPUT:TEXT FORM=ACTION:account_address_edit2.php ATTR=NAME:Negara CONTENT={{!COL2}}
    TAG POS=1 TYPE=INPUT:TEXT FORM=ACTION:account_address_edit2.php ATTR=NAME:Bangsa CONTENT={{!COL3}}
    TAG POS=1 TYPE=INPUT:TEXT FORM=ACTION:account_address_edit2.php ATTR=NAME:Budaya CONTENT={{!COL4}}
    WAIT SECONDS=5
    4. test.csv (this table has 4 columns but I only took 2 columns in the screenshot)

    View attachment 46738
     
  5. E=MC²

    E=MC² Junior Member

    Joined:
    Apr 12, 2013
    Messages:
    176
    Likes Received:
    183
    In your first post, you wrote that the first one (PasteData.iim) should paste "Sam/..." and the second one should paste the country then in your other post you linked two identical codes. If they both do the same thing they can be merged in one.
    And also you said you have 200 "Data", what is that supposed to mean? 200 of which one? each one of them? or both of them?
    Anyway, with the info you provided this is as far as I can help you:
    Code:
    for (var account=1; account<=74; account++)
    {
    iimSet ("account", account); // Use this variable in login.iim to loop through the accounts
    iimPlay ("LoginA.iim");
    /* Add a loop (Or 2 loops, it depends on what you're trying to accomplish I can't really tell) for these two functions that will loop through the data from, use iimSet in the same way i did */
          iimPlay ("PasteData.iim");
          iimPlay ("AnotherPasteData.iim");
    }
    
     
  6. hillz

    hillz Registered Member

    Joined:
    Aug 14, 2011
    Messages:
    54
    Likes Received:
    3
    I'm sorry for not being clear last time mate, can you run this code in your computer?

    1. Datasource.iim
    Code:
    VERSION BUILD=8240212 RECORDER=FX
    TAB T=1
    'SET !REPLAYSPEED SLOW
    SET !ERRORIGNORE YES
    SET !TIMEOUT_STEP 0
    SET !DATASOURCE test.csv
    SET !DATASOURCE_COLUMNS 4
    SET !DATASOURCE_LINE {{!LOOP}} 
    SET !LOOP {{myLoop}}
    SET !EXTRACT_TEST_POPUP NO
    SET !TIMEOUT 60
    
    
    URL GOTO=galihpa.tk
    TAG POS=1 TYPE=INPUT:TEXT FORM=ID:usrform ATTR=NAME:usrname CONTENT={{!COL1}}
    TAG POS=2 TYPE=INPUT:TEXT FORM=ID:usrform ATTR=NAME:usrname CONTENT={{!COL2}}
    TAG POS=3 TYPE=INPUT:TEXT FORM=ID:usrform ATTR=NAME:usrname CONTENT={{!COL3}}
    
    
    TAG POS=1 TYPE=INPUT:TEXT FORM=ID:usrform ATTR=VALUE:* EXTRACT=TXT
    TAG POS=2 TYPE=INPUT:TEXT FORM=ID:usrform ATTR=VALUE:* EXTRACT=TXT
    TAG POS=3 TYPE=INPUT:TEXT FORM=ID:usrform ATTR=VALUE:* EXTRACT=TXT
    2. Job.iim
    Code:
    URL GOTO=galihpa.tk/test
    TAG POS=1 TYPE=INPUT:TEXT FORM=ID:usrform ATTR=NAME:usrname CONTENT={{myData1}}
    TAG POS=2 TYPE=INPUT:TEXT FORM=ID:usrform ATTR=NAME:usrname CONTENT={{myData2}}
    TAG POS=3 TYPE=INPUT:TEXT FORM=ID:usrform ATTR=NAME:usrname CONTENT={{myData3}}
    WAIT SECONDS=5
    3. test.js
    Code:
    var i;
    var data1;
    var data2;
    var data3;
    var data4;
    var data5;
    var data6;
    var data7;
    
    
    for (i = 1; i < 5; i++)
        {
            function myFunction()
                {
                    iimSet ("myLoop",i);
                    iimPlay ("Datasource.iim");
                    
                    data1 = iimGetLastExtract(1);
                    data2 = iimGetLastExtract(2);
                    data3 = iimGetLastExtract(3);
                    
                    iimSet ("myData1", data1);
                    iimSet ("myData2", data2);
                    iimSet ("myData3", data3);
                    
                    iimPlay ("Job.iim");
                }
            myFunction()
        }
    And here's the test.csv file

    Please run that test.js file, you'll notice that on the first-last loop, the extracted data is always like this:
    1. address1
    2. zip1
    3. city1

    What I want is like this:
    First loop:
    1. address1
    2. zip1
    3. city1

    Second loop:
    1. address2
    2. zip2
    3. city2

    Third Loop:
    1. address3
    2. zip3
    3. city3

    I hope this is easier to understand. Please tell me where I went wrong with that script.
    Thanks.
     
  7. hillz

    hillz Registered Member

    Joined:
    Aug 14, 2011
    Messages:
    54
    Likes Received:
    3
    SOLVED

    Damn, I should have noticed. I made a simple mistake.
    In Datasource.iim I have the following:

    Code:
    SET !DATASOURCE_LINE {{!LOOP}} 
    SET !LOOP {{myLoop}}
    
    I should first SET the !LOOP then SET the !DATASOURCE. So the entire code will be like this:

    Code:
    VERSION BUILD=8240212 RECORDER=FX
    TAB T=1
    'SET !REPLAYSPEED SLOW
    SET !ERRORIGNORE YES
    SET !TIMEOUT_STEP 0
    SET !DATASOURCE test.csv
    SET !DATASOURCE_COLUMNS 4
    SET !LOOP {{myLoop}}
    SET !DATASOURCE_LINE {{!LOOP}} 
    SET !EXTRACT_TEST_POPUP NO
    SET !TIMEOUT 60
    
    
    
    
    URL GOTO=galihpa.tk
    TAG POS=1 TYPE=INPUT:TEXT FORM=ID:usrform ATTR=NAME:usrname CONTENT={{!COL1}}
    TAG POS=2 TYPE=INPUT:TEXT FORM=ID:usrform ATTR=NAME:usrname CONTENT={{!COL2}}
    TAG POS=3 TYPE=INPUT:TEXT FORM=ID:usrform ATTR=NAME:usrname CONTENT={{!COL3}}
    
    
    
    
    TAG POS=1 TYPE=INPUT:TEXT FORM=ID:usrform ATTR=VALUE:* EXTRACT=TXT
    TAG POS=2 TYPE=INPUT:TEXT FORM=ID:usrform ATTR=VALUE:* EXTRACT=TXT
    TAG POS=3 TYPE=INPUT:TEXT FORM=ID:usrform ATTR=VALUE:* EXTRACT=TXT
    
    Thanks to Mr.Profit for his assistance through PM. I really appreciate his help :D
     
  8. SEO Ustad

    SEO Ustad Regular Member

    Joined:
    Sep 19, 2013
    Messages:
    271
    Likes Received:
    52
    Home Page:
    You can used JS is best way to improved you're success rate in macros.
     
    • Thanks Thanks x 1