Cpher Cass
Cpher Cass

Reputation: 51

imacros javascript if else not behaving as it should and more

OKay first off I had the perfect script, but their was no way to run a else conditions so had to parlay everything in the javascript somewhat but now the scripts runs but not as intended.

const iterations = 100; // Number of times to loop

for (var i=0; i<iterations; i++){
iimSet('iteration', i );
iimPlay('Step1'); // PART ONE, Grabs the varibles and sets everything up.


var string = "Error, Invalid Request.";
var result = string.match(/error/i);
// result == 'ERROR';

 if (result){
 iimPlay(Step1'); // PART TWO Checks to see if it was successful if not then Loop back                       to Step One but if it was Goes on to Step 3
 }    



  else {
  iimPlay('Step2');}}  // PART THREE, this is the last step and save all extracts.

Everything triggers but does not execute like it should. For Example. On "PART ONE" we call an iim Step1 where we set our varibles etc (where everything worked before javascript) and it runs like it should perfectly. The problem comes to play on "STEP TWO, no matter if it detects that string or not it will still fireoff and re-LOOP which it shouldent.

PART THREE when I manipulate the script to make it to PART THREE to test it, when it complete it LOOPS but does not update the {{COLS}} or the !VAR1 like it should, even thought everything is fine.

Anyhelp please, I was too proud to beg at first but its been about a few days over that obbessed point and I just need help, Cant figure it out on my own.

Upvotes: 1

Views: 3013

Answers (1)

edinvnode
edinvnode

Reputation: 3547

You didn't explain well your question.

Try this out. If the Step1 macro has SET !ERRORIGNORE YES in it that case macro always returns value true when played.

Try out this model

var macro;

macro ="CODE:";
macro +="TAG POS=1 TYPE=A ATTR=HREF:www.somelink.com EXTRACT=HREF";

var macro1;

macro1 ="CODE:";
macro1 +="TAG POS=1 TYPE=A ATTR=HREF:www.somelink1.com EXTRACT=HREF";




var result=null;

result=iimPlay(macro);

//error has negative value
if(result<0)
{
//do something
}
else
{
iimPlay(macro1)
}

Also here you have a list of errors and their explanation. http://wiki.imacros.net/Error_and_Return_Codes

You can use it like this.

var result=null;

result=iimPlay(somemacro);

if(result==-1001)
{
alert("Error happened. Error type: Syntax error in XPath expression");
}

Upvotes: 1

Related Questions