PERL $b->iimGetLastErrorMessage() method returns "undef"

Discussions and Tech Support related to automating the iMacros Browser or Internet Explorer from any scripting and programming language, such as VBS (WSH), VBA, VB, Perl, Delphi, C# or C++.
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
mguttman
Posts: 31
Joined: Sat Jan 09, 2010 7:32 pm

PERL $b->iimGetLastErrorMessage() method returns "undef"

Post by mguttman » Wed Mar 24, 2010 5:47 pm

Dear iOpus folks

I am using iMacro mainly embedded in PERL scripts, where most of these are invoked by a scheduler, unattended. Nicely enough, iOpus provided a scripting interface class to iMacro to a number of languages, including PERL.

Since Internet sites responses are not 100% reliable, too often a macro hangs. When the macro is manually invoked, this is not much of a problem, you give it up and "play" it again.

But if the script is automatically invoked, unattended, this is a serious problem! so there are two issues:

1) Can I specify a time-out to have iMacro return control to the PERL script?

2) One method of the PERL class which is very important to this unattended application is the iimGetLastErrorMessage() method.

The last one is supposed to return an error message. In another post I mentioned that it always returns the "undef" value. In that post things didn't work at all so this one was considered a minor issue. Luckily, the more important issue there was satisfactorily solved. We were so happy about it that we ignored this one. But it is not minor. So please, how do we fix this?

Can you help?

Regards,
Meir
Regards,
Meir
mguttman
Posts: 31
Joined: Sat Jan 09, 2010 7:32 pm

Re: PERL $b->iimGetLastErrorMessage() method returns "undef"

Post by mguttman » Sat Mar 27, 2010 8:00 am

Hi, me again!

I tried the iimGetLastError() method too. Although this one returns a defined value, the value is always zero!

What do I do wrong???

Regards,
Meir
Regards,
Meir
mguttman
Posts: 31
Joined: Sat Jan 09, 2010 7:32 pm

Re: PERL $b->iimGetLastErrorMessage() method returns "undef"

Post by mguttman » Sun Mar 28, 2010 5:10 pm

Hi everybody,

(It seems I am corresponding with myself only... :wink: !)

Well, I made some progress! I now use the "Return Code" of the scripting interface to find the result of the operation.

My PERL script shows some unexpected behavior:
* iimInit seems to consistently return the OK code - "1"
* iimPlay however returned once "-930" and then consistently "-971"

Despite the negative (i.e., error) last return code, the macro seems to work just fine, thank you!

I tried though to find the list of return codes. The obvious place was the Error and Return Codes Wiki Page. Down there there is the following "bullet":
# -100...-999 (sMacroError)
sMacroError can have a value of -100 and lower (-101,-102,...,-999). These are NOT Scripting Interface error codes, but errors created by the iMacros browser and the macro itself. The Scripting Interface passes them from the browser to your script or application.
All links in that bullet point to itself. Very frustrating. Half an hour of search resulted in zilch.

Pray tell me what are the meanings of these codes...
Regards,
Meir
Daniel, Tech Support
Posts: 1483
Joined: Tue Jan 26, 2010 11:35 am

Re: PERL $b->iimGetLastErrorMessage() method returns "undef"

Post by Daniel, Tech Support » Tue Mar 30, 2010 12:54 pm

Hi Meir,

Sorry for the delay. iimGetLastError will only return an error code if an error has really occured :) I.e. if a TAG command failed etc.
Have you tried in it Perl on a macro that definitely fails, e.g.

Code: Select all

URL GOTO=http://www.google.com
TAG POS=1 TYPE=A ATTR=TXT:microsoft
?

I will now look into the error codes.

Best regards,
Daniel, iOpus Support
Daniel, Tech Support
Posts: 1483
Joined: Tue Jan 26, 2010 11:35 am

Re: PERL $b->iimGetLastErrorMessage() method returns "undef"

Post by Daniel, Tech Support » Tue Mar 30, 2010 4:48 pm

With regards to the error codes, we will update the wiki shortly.
Daniel, iOpus Support
mguttman
Posts: 31
Joined: Sat Jan 09, 2010 7:32 pm

Re: PERL $b->iimGetLastErrorMessage() method returns "undef"

Post by mguttman » Thu Apr 01, 2010 3:33 pm

Dear Daniel,

Well, it seems that my computer is jinxed or something! What works at your end doesn't at mine... :evil: Did you actually ran it from Perl?

I did try to find "Microsoft" on the Google page. Running iMacro directly from FF indeed ended with Error:
"RuntimeError: element A specified by TXT:microsoft was not found, line: 4"
However, running it from PERL did the following:
* The "Return code" was -921
* iimGetLastErrorMessage returned UNDEF.

(BTW, the "Return Codes" for iimPlay() and the other scripting I/F are still missing.)
Regards,
Meir
Daniel, Tech Support
Posts: 1483
Joined: Tue Jan 26, 2010 11:35 am

Re: PERL $b->iimGetLastErrorMessage() method returns "undef"

Post by Daniel, Tech Support » Thu Apr 01, 2010 9:14 pm

Hi Meir,

No, I didn't mean that code worked on my machine with Perl, I wanted to ask you if it does on your. I will try to reproduce it here then (will need to install Perl again as I've got a new machine :)) and give you an update.

Best regards,
Daniel, iOpus Support
Daniel, Tech Support
Posts: 1483
Joined: Tue Jan 26, 2010 11:35 am

Re: PERL $b->iimGetLastErrorMessage() method returns "undef"

Post by Daniel, Tech Support » Mon Apr 12, 2010 6:14 pm

Hi Meir,

This code (a modified version of the script you once posted) works and returns correct value:

Code: Select all

    use strict;
    use Win32::OLE;
    print "Just started\n";
    my $b = Win32::OLE->new("imacros") or die "iMacros Browser could not be started by Win32:OLE\n";
    $b->{Visible} = 1;
    print "After invoking the OLE\n";
    sleep 10;
    # Start the iMacros Browser - Use iimInit("-ie"/"-fx") to start iMacros for IE/Firefox instead.
    $b->iimInit("-fx");
    print "After iimInit\n";
    sleep 10;
    my $macro = 'C:\\Users\\Daniel\\Documents\\Client Scripts\\Perl\\iim.iim';
    print "\$macro = $macro\n";
    $b->iimPlay($macro);
    print "After 'playing' the iMacro\n";
    sleep 10;
    print $b->iimGetLastError();
    $b->iimExit();
Could you please try it with this macro:

Code: Select all

URL GOTO=http://www.google.com
TAG POS=1 TYPE=A ATTR=TXT:ahdkjsahdjahs
URL GOTO=http://www.google.com
Best regards,
Daniel, iOpus Support
mguttman
Posts: 31
Joined: Sat Jan 09, 2010 7:32 pm

Re: PERL $b->iimGetLastErrorMessage() method returns "undef"

Post by mguttman » Tue Apr 13, 2010 10:15 am

Hello, hello Daniel!

Hurray! Congratulations, it is working!

But now, please tell me what was changed??? For the life of me, I couldn't see any material difference to the original post.

Or did iMacro change? I am not aware of any upgrade to iMacro lately. Or is it silently upgraded?

Please enlighten,
Regards,
Meir
Daniel, Tech Support
Posts: 1483
Joined: Tue Jan 26, 2010 11:35 am

Re: PERL $b->iimGetLastErrorMessage() method returns "undef"

Post by Daniel, Tech Support » Wed Apr 14, 2010 7:41 pm

Hi Meir,

No there were no updates to iMacros :)

See, my knowledge of Perl is quite limited, so I don't really know what was wrong with

Code: Select all

sub err {
    $lastMessage = $b->iimGetLastErrorMessage();
        if ($lastMessage =~ /Macro completed/) {
            print("Success <$macro> $lastMessage\n");
            #write a logger here for Success $lastMessage
        }
         else{
              print("Failure <$macro> $lastMessage\n");
              #write a logger here for Failure $lastMessage
             } 
}
It seems to be absolutely fine... May be something with operator precedence? I don't think so... I just simplified it as much as I could and... it worked... :)
Daniel, iOpus Support
mguttman
Posts: 31
Joined: Sat Jan 09, 2010 7:32 pm

Re: PERL $b->iimGetLastErrorMessage() method returns "undef"

Post by mguttman » Thu Apr 15, 2010 10:10 am

Hi Daniel!

That's odd! I simplified it long ago. In fact, I looked at the original code deposited in my very first post and the sub() part was already commented out. So, as I said, for the life of me I cannot explain it...

Well, at least it works!

Thanks Daniel!
Regards,
Meir
Daniel, Tech Support
Posts: 1483
Joined: Tue Jan 26, 2010 11:35 am

Re: PERL $b->iimGetLastErrorMessage() method returns "undef"

Post by Daniel, Tech Support » Fri Apr 16, 2010 12:03 pm

Hi Meir,

May be I will investigate more when I have some time to play with Perl :) But for now I would leave it... working :)

Best wishes!
Daniel, iOpus Support
mathewbeall
Posts: 1
Joined: Sun Jun 20, 2010 5:47 pm

Re: PERL $b->iimGetLastErrorMessage() method returns "undef"

Post by mathewbeall » Sun Jun 20, 2010 5:49 pm

Not sure if this was answered yet - but in your original post you had "iimGetLastErrorMessage" - and in the code that worked, it was just "iimGetLastError"


Matt
mguttman
Posts: 31
Joined: Sat Jan 09, 2010 7:32 pm

Re: PERL $b->iimGetLastErrorMessage() method returns "undef"

Post by mguttman » Mon Jun 21, 2010 12:47 pm

Dear Matt,

Well, not exactly answered yet. What I use now is

Code: Select all

$play_iret = $b->iimPlay($macro_name, 60)
to get the result code in $play_iret. But it often gives very little information. Basically, if it finished OK ($play_iret == 1) or not. If it didn't, I have very little to go on.

For example, I often get a -971 error code but I couldn't find any explanation as what might cause it.
Regards,
Meir
tomotello
Posts: 3
Joined: Mon Aug 28, 2017 3:34 pm
Location: Switzerland, Basel

Re: PERL $b->iimGetLastErrorMessage() method returns "undef"

Post by tomotello » Sun Sep 03, 2017 5:35 pm

From the Wiki Reference http://wiki.imacros.net/Command_Referen ... d_Overview it's actually iimGetErrorText() while iimGetLastError() seems to be old (obviously still working). However, the Perl Example on the Wiki still has iimGetLastErrorMessag() which seems to be a typo since the example has been published.
To get the err() function in the example to work - as actually tested with iMacros v12 - validation has to be adapted to check for /^OK/ instead of /Macro completed/.

To make the long story short, here is a fixed sub err () with the 2 wrong lines commented out (the fixed entire script is attached):

Code: Select all

########################################################################
 # Get the last message reported from iMacros upon macro completion status#
 ########################################################################
 sub err {
    # $lastMessage = $b->iimGetLastErrorMessage();
    $lastMessage = $b->iimGetErrorText(); 
          # if ($lastMessage =~ /Macro completed/) {
          if ($lastMessage =~ /^OK/) {
            print("Success <$macro> $lastMessage\n");
            #write a logger here for Success $lastMessage
        }
         else{
              print("Failure <$macro> $lastMessage\n");
              #write a logger here for Failure $lastMessage
             }  
 }
Attachments
iMacros_Perl_Example_fixed.zip
Fixed Error Handling for Perl Example
(824 Bytes) Downloaded 358 times
Post Reply