Reputation: 63
English isn’t my first language, so please forgive any mistakes.
FCIM : I'm using iMacros v9.0.3 on Firefox 53.0.3 (64 bit) in Windows 8 x64
I'm trying to loop the JavaScript code in iMacros with a Datasource
.
It's working fine when it's just iim (iMacro) code.
It perfectly enters the right value in the right row number.
But after I convert the script from iim into JavaScript, it doesn't enter the data correctly.
for eg, in iMacro code when I loop, it rightly enters row by row data:
loop1 - kannan1
loop2 - kannan2
loop3 - kannan3 ...
But after I convert it into JavaScript, it always enters THE SAME DATA over and over again.
loop1 - kannan1
loop2 - kannan1
loop3 - kannan1 ...
Here is my Datasource demo.csv
Here is an iim code example
VERSION BUILD=9030808 RECORDER=FX
TAB T=1
TAB CLOSEALLOTHERS
SET !DATASOURCE demo.csv
SET !DATASOURCE_COLUMNS 8
SET !DATASOURCE_LINE {{!LOOP}}
SET !LOOP 1
URL GOTO=http://demo.imacros.net/Automate/AutoDataEntry
TAG POS=1 TYPE=INPUT:TEXT FORM=ID:demo ATTR=ID:fname CONTENT={{!COL1}}
TAG POS=1 TYPE=INPUT:TEXT FORM=ID:demo ATTR=ID:lname CONTENT={{!COL2}}
TAG POS=1 TYPE=INPUT:TEXT FORM=ID:demo ATTR=ID:address CONTENT={{!COL3}}
TAG POS=1 TYPE=INPUT:TEXT FORM=ID:demo ATTR=ID:city CONTENT={{!COL4}}
TAG POS=1 TYPE=INPUT:TEXT FORM=ID:demo ATTR=ID:zip CONTENT={{!COL5}}
TAG POS=1 TYPE=SELECT FORM=ID:demo ATTR=ID:state CONTENT=%IN
TAG POS=1 TYPE=SELECT FORM=ID:demo ATTR=ID:country CONTENT=%73
TAG POS=1 TYPE=INPUT:TEXT FORM=ID:demo ATTR=ID:email CONTENT={{!COL8}}
TAG POS=1 TYPE=BUTTON FORM=ID:demo ATTR=TXT:Submit
Here is a Javascript example code
var macro;
macro = "CODE:";
for(var X = 1; X <= 10; X++){
macro += "TAB T=1" + "\n";
macro += "TAB CLOSEALLOTHERS" + "\n";
macro += "SET !DATASOURCE demo.csv" + "\n";
macro += "SET !DATASOURCE_COLUMNS 8" + "\n";
macro += "SET !DATASOURCE_LINE {{!LOOP}} " + "\n";
macro += "SET !LOOP 1" + "\n"
macro += "URL GOTO=http://demo.imacros.net/Automate/AutoDataEntry" + "\n";
macro += "TAG POS=1 TYPE=INPUT:TEXT FORM=ID:demo ATTR=ID:fname CONTENT={{!COL1}}" + "\n";
macro += "TAG POS=1 TYPE=INPUT:TEXT FORM=ID:demo ATTR=ID:lname CONTENT={{!COL2}}" + "\n";
macro += "TAG POS=1 TYPE=INPUT:TEXT FORM=ID:demo ATTR=ID:address CONTENT={{!COL3}}" + "\n";
macro += "TAG POS=1 TYPE=INPUT:TEXT FORM=ID:demo ATTR=ID:city CONTENT={{!COL4}}" + "\n";
macro += "TAG POS=1 TYPE=INPUT:TEXT FORM=ID:demo ATTR=ID:zip CONTENT={{!COL5}}" + "\n";
macro += "TAG POS=1 TYPE=SELECT FORM=ID:demo ATTR=ID:state CONTENT=%IN" + "\n";
macro += "TAG POS=1 TYPE=SELECT FORM=ID:demo ATTR=ID:country CONTENT=%73" + "\n";
macro += "TAG POS=1 TYPE=INPUT:TEXT FORM=ID:demo ATTR=ID:email CONTENT={{!COL8}}" + "\n";
macro += "TAG POS=1 TYPE=BUTTON FORM=ID:demo ATTR=TXT:Submit" + "\n";
iimPlay(macro)
}
iimPlay(macro)
Any ideas on how to make it loop correctly? and thx in advance to all my brothers :)
Upvotes: 0
Views: 362
Reputation: 32370
The following is a simple example demonstrating the issue in pseudo-code
## Code connection = new DatabaseConnection; print connection.currentrow.firstname; print connection.currentrow.lastname; print connection.currentrow.age; connection.getNextRow(); ## Result Alice Anderson 33
## Code mycode = ""; for ixx in range(0 .. 3): mycode += "connection = new DatabaseConnection;" //<--MISTAKE mycode += "print connection.currentrow.firstname;" mycode += "print connection.currentrow.lastname;" mycode += "print connection.currentrow.age;" mycode += "connection.getNextRow();" myApp.run(mycode);
## Actual Result Alice Anderson 33 Alice Anderson 33 Alice Anderson 33 Alice Anderson 33 ## Desired Result Alice Anderson 33 Bob Banderson 44 Charlie Chanderson 55 Danny Danderson 66 ## BROKEN ;; Actual Result does not match desired result, because ## the DatabaseConnection gets reset every time.
## Fixed code mycode = ""; mycode += "connection = new DatabaseConnection;" //<-- FIXED MISTAKE for ixx in range(0 .. 3): mycode += "print connection.currentrow.firstname;" mycode += "print connection.currentrow.lastname;" mycode += "print connection.currentrow.age;" mycode += "connection.getNextRow();" myApp.run(mycode);
The same mistake seems to be repeated here. These lines should not be inside the loop.
SET !DATASOURCE demo.csv SET !DATASOURCE_COLUMNS 8
Upvotes: 1