Using SET !VAR1 EVAL with javascript iMacros

Support for iMacros. The iMacros software is the unique solution for automating every activity inside a web browser, for data extraction and web testing.

Moderators: Community Moderators, iMacros Moderators

Forum rules
Before asking a question or reporting an issue:
1. Please review the list of FAQ's.
2. Use the Google search box (at the top of each forum page) to see if a similar problem or question has already been addressed. This will search the entire contents of the forums as well as the iMacros Wiki.
3. We can respond much faster to your posts if you include the following information:

CLICK HERE FOR IMPORTANT INFORMATION TO INCLUDE IN YOUR POST

Answering your own posts (e.g. attempting to "bump" your topic) drops your topic from the list of unanswered threads, so it may actually receive less views.

Using SET !VAR1 EVAL with javascript iMacros

by jinjinda on Thu Nov 30, 2017 2:04 am

I have a .js iMacros file for go to url, it looks like this:

Code: Select all
for ( var k = 0; k<3; k++){
var congdong;
congdong =  "CODE:";
congdong +=  "VERSION BUILD=8970419 RECORDER=FX" + "\n";
congdong +=  "SET !ERRORIGNORE YES" + "\n";
congdong +=  "SET !VAR1 EVAL(\"var letters = ['link1','link2','link3','link4','link5','link6','link7','link8']; var  results = []; for (var i = 0; i < 3; i++) {var pos = parseInt(Math.random()  * (letters.length - 1));results.push(letters[pos]);letters.splice(pos, 1);} results[i];\")" + "\n";
congdong +=  "TAB T=1" + "\n";
congdong +=  "URL GOTO={{!VAR1}}" + "\n";
iimPlay(congdong)
}


My goal is for it to run 3 times each time going to 1 different url. But when I let it run it does not go to any urls and does not report errors. Any ideas on how I could get this working?

Thanks so much!
jinjinda
 
Posts: 3
Joined: Mon Nov 27, 2017 10:15 pm

Re: Using SET !VAR1 EVAL with javascript iMacros

by chivracq on Thu Nov 30, 2017 12:13 pm

jinjinda wrote:I have a .js iMacros file for go to url, it looks like this:

Code: Select all
for ( var k = 0; k<3; k++){
var congdong;
congdong =  "CODE:";
congdong +=  "VERSION BUILD=8970419 RECORDER=FX" + "\n";
congdong +=  "SET !ERRORIGNORE YES" + "\n";
congdong +=  "SET !VAR1 EVAL(\"var letters = ['link1','link2','link3','link4','link5','link6','link7','link8']; var  results = []; for (var i = 0; i < 3; i++) {var pos = parseInt(Math.random()  * (letters.length - 1));results.push(letters[pos]);letters.splice(pos, 1);} results[i];\")" + "\n";
congdong +=  "TAB T=1" + "\n";
congdong +=  "URL GOTO={{!VAR1}}" + "\n";
iimPlay(congdong)
}


My goal is for it to run 3 times each time going to 1 different url. But when I let it run it does not go to any urls and does not report errors. Any ideas on how I could get this working?

Thanks so much!

FCIM...! :mrgreen: (Read my Sig...)
=> iMacros for FF v8.9.7...?, FF55/56...?, OS...?

Ouf-ouf-ouf...!, what a complicated "Solution" you have in your 'EVAL()' Statement...! If you created yourself, you should be able to find "a" (much easier!) Solution by yourself, I would think..., like simply using your Random Nb for the Index 'n' on your 'letters[n]' Array... :idea:
- (F)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all 3 Versions...
- I usually don't even read the Question if that (required) Info is not mentioned...
- Script & URL usually help a lot for a more "educated" Help...
chivracq
 
Posts: 6473
Joined: Sat Apr 13, 2013 6:07 am
Location: Amsterdam (NL)

Re: Using SET !VAR1 EVAL with javascript iMacros

by jinjinda on Thu Nov 30, 2017 6:23 pm

chivracq wrote:
jinjinda wrote:I have a .js iMacros file for go to url, it looks like this:

Code: Select all
for ( var k = 0; k<3; k++){
var congdong;
congdong =  "CODE:";
congdong +=  "VERSION BUILD=8970419 RECORDER=FX" + "\n";
congdong +=  "SET !ERRORIGNORE YES" + "\n";
congdong +=  "SET !VAR1 EVAL(\"var letters = ['link1','link2','link3','link4','link5','link6','link7','link8']; var  results = []; for (var i = 0; i < 3; i++) {var pos = parseInt(Math.random()  * (letters.length - 1));results.push(letters[pos]);letters.splice(pos, 1);} results[i];\")" + "\n";
congdong +=  "TAB T=1" + "\n";
congdong +=  "URL GOTO={{!VAR1}}" + "\n";
iimPlay(congdong)
}


My goal is for it to run 3 times each time going to 1 different url. But when I let it run it does not go to any urls and does not report errors. Any ideas on how I could get this working?

Thanks so much!

FCIM...! :mrgreen: (Read my Sig...)
=> iMacros for FF v8.9.7...?, FF55/56...?, OS...?

Ouf-ouf-ouf...!, what a complicated "Solution" you have in your 'EVAL()' Statement...! If you created yourself, you should be able to find "a" (much easier!) Solution by yourself, I would think..., like simply using your Random Nb for the Index 'n' on your 'letters[n]' Array... :idea:

yes sorry.
FF 30.0 iMacros 8.9.7 OS win 7 64bit
jinjinda
 
Posts: 3
Joined: Mon Nov 27, 2017 10:15 pm

Re: Using SET !VAR1 EVAL with javascript iMacros

by chivracq on Thu Nov 30, 2017 10:06 pm

jinjinda wrote:yes sorry.
Code: Select all
FF 30.0  iMacros 8.9.7  OS win 7 64bit

OK for your FCI...
Hum, a bit strange btw, FF30...!?, hum OK, yep possible, v8.8.8 until FF29 and v8.9.x from FF30 indeed, so yep I guess v8.9.7 should work on FF30...
But any Reason why you staid at FF30...? :?
v8.9.7 still works perfectly until at least FF v55.0.3 (FF Version I use myself with v8.9.7 for FF)...

But otherwise, any Reaction on the "Content" of your Thread and my Suggestion/Solution about your 'letters[n]'...!?

Ah but OK, ah-ah...!, I see you opened a parallel Thread on SOF, OK, no Pb..., my Sol is actually the same like the one from @Shugar, ah-ah...!, the one from @Naren Murali might work but hum, it looks to me as complicated as your original post...

Hum, I see some " thanks you so much. I solved my problem – Jinjin Da 26 mins ago " from you, you would need to accept one of the 2 Sols and/or share your own Sol on SOF to finish that Thread correctly on SOF, and to do the same here on our Forum by sharing "your" Sol and posting your Final Script... :idea:
- (F)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all 3 Versions...
- I usually don't even read the Question if that (required) Info is not mentioned...
- Script & URL usually help a lot for a more "educated" Help...
chivracq
 
Posts: 6473
Joined: Sat Apr 13, 2013 6:07 am
Location: Amsterdam (NL)

Re: Using SET !VAR1 EVAL with javascript iMacros

by jinjinda on Thu Nov 30, 2017 11:35 pm

Yes, this my code running
Code: Select all
var linkcd= [
  'link1',
  'link2',
  'link3',
  'link4',
  'link5',
  'link6',
  'link7'
];
var resultscd = [];
for (var k = 0; k < 6; k++) {
  var pos = parseInt(Math.random() * (linkcd.length - 1));
  resultscd.push(linkcd[pos]);
  linkcd.splice(pos, 1);
}

for (var k = 0; k < 3; k++) {
var congdong;
congdong =  "CODE:";
congdong +=  "VERSION BUILD=8970419 RECORDER=FX" + "\n";
congdong +=  "SET !ERRORIGNORE YES" + "\n";
congdong +=  "SET !VAR1 \"" + resultscd[k] + "\"\n";
congdong +=  "TAB T=1" + "\n";
congdong +=  "URL GOTO={{!VAR1}}" + "\n";
iimPlay(congdong)
jinjinda
 
Posts: 3
Joined: Mon Nov 27, 2017 10:15 pm

Re: Using SET !VAR1 EVAL with javascript iMacros

by chivracq on Fri Dec 01, 2017 12:45 pm

jinjinda wrote:Yes, this my code running
Code: Select all
var linkcd= [
  'link1',
  'link2',
  'link3',
  'link4',
  'link5',
  'link6',
  'link7'
];
var resultscd = [];
for (var k = 0; k < 6; k++) {
  var pos = parseInt(Math.random() * (linkcd.length - 1));
  resultscd.push(linkcd[pos]);
  linkcd.splice(pos, 1);
}

for (var k = 0; k < 3; k++) {
var congdong;
congdong =  "CODE:";
congdong +=  "VERSION BUILD=8970419 RECORDER=FX" + "\n";
congdong +=  "SET !ERRORIGNORE YES" + "\n";
congdong +=  "SET !VAR1 \"" + resultscd[k] + "\"\n";
congdong +=  "TAB T=1" + "\n";
congdong +=  "URL GOTO={{!VAR1}}" + "\n";
iimPlay(congdong)

OK, good...!, Thanks for sharing, on our Forum and on SOF... :D

I still find it a bit cumbersome, @Shugar's and my Solution was much simpler I would think, the 'push()' and 'splice()' are probably not needed, even if it's a nice "Exercise", ah-ah...!, as those 2 Commands are not often used, but I guess if your Script works, then you're already happy... :wink:

There was no real "Need" from your original Script to use a '.js' Script, but you went for a "full" '.js' Solution, meaning your Script will only work in FF, while handling your Requirement directly from the 'EVAL()' like @Shugar and myself suggested would have allowed your Script to work in all 4 Browsers supported by iMacros... But fair enough...! 8)
- (F)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all 3 Versions...
- I usually don't even read the Question if that (required) Info is not mentioned...
- Script & URL usually help a lot for a more "educated" Help...
chivracq
 
Posts: 6473
Joined: Sat Apr 13, 2013 6:07 am
Location: Amsterdam (NL)


Return to General Support & Discussions

Who is online

Users browsing this forum: No registered users and 8 guests

-->