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.
Forum rules
iMacros EOL - Attention!

The renewal maintenance has officially ended for Progress iMacros effective November 20, 2023 and all versions of iMacros are now considered EOL (End-of-Life). The iMacros products will no longer be supported by Progress (aside from customer license issues), and these forums will also no longer be moderated from the Progress side.

Thank you again for your business and support.

Sincerely,
The Progress Team

Before asking a question or reporting an issue:
1. Please review the list of FAQ's.
2. Use the search box (at the top of each forum page) to see if a similar problem or question has already been addressed.
3. Try searching the iMacros Wiki - it contains the complete iMacros reference as well as plenty of samples and tutorials.
4. We can respond much faster to your posts if you include the following information: CLICK HERE FOR IMPORTANT INFORMATION TO INCLUDE IN YOUR POST
Post Reply
jinjinda
Posts: 4
Joined: Tue Nov 28, 2017 5:15 am

Using SET !VAR1 EVAL with javascript iMacros

Post by jinjinda » Thu Nov 30, 2017 9: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!
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Using SET !VAR1 EVAL with javascript iMacros

Post by chivracq » Thu Nov 30, 2017 7: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)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE'/'Trial').
- FCI not mentioned: I don't even read the Qt...! (or only to catch Spam!)
- Script & URL help a lot for more "educated" Help...
jinjinda
Posts: 4
Joined: Tue Nov 28, 2017 5:15 am

Re: Using SET !VAR1 EVAL with javascript iMacros

Post by jinjinda » Fri Dec 01, 2017 1:23 am

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
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Using SET !VAR1 EVAL with javascript iMacros

Post by chivracq » Fri Dec 01, 2017 5:06 am

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)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE'/'Trial').
- FCI not mentioned: I don't even read the Qt...! (or only to catch Spam!)
- Script & URL help a lot for more "educated" Help...
jinjinda
Posts: 4
Joined: Tue Nov 28, 2017 5:15 am

Re: Using SET !VAR1 EVAL with javascript iMacros

Post by jinjinda » Fri Dec 01, 2017 6:35 am

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)
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Using SET !VAR1 EVAL with javascript iMacros

Post by chivracq » Fri Dec 01, 2017 7: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)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE'/'Trial').
- FCI not mentioned: I don't even read the Qt...! (or only to catch Spam!)
- Script & URL help a lot for more "educated" Help...
Post Reply