Run downloaded macros and collect execution

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
thiagunix
Junior Coder
Posts: 23
Joined: Tue May 05, 2020 2:16 pm

Run downloaded macros and collect execution

Post by thiagunix » Mon Jul 13, 2020 7:53 pm

Hello,

I made a routine that accesses a url, downloads a macro and executes it, enters the url again, downloads another macro and stays there until there is no macro to download.

However I need to know if each execution was successful or had an error.

The problem is that if I use ExecuteFile> it does not collect errors.
When I use Include> it collects the right error, but when I download the other macro it loads into memory because it already has one.

Thanks

Code: Select all

Let>lin=0
Let>MACROS=http://url.com.br/mdj.php
Let>ONERROR=MyErrs

Let>FILEEXEC=%TEMP_DIR%mje_temp.scp
Let>IGNORESPACES=1

// CHECK IF YOU HAVE MACRO FOR EXECUTION
HTTPRequest>MACROS,,GET,,MJD
IF>MJD<>
  Repeat>lin
  
    // DATA COLLECTION
    HTTPRequest>MACROS,,GET,,MJD

    IF>MJD<>
          // DOWNLOAD MACRO
      HTTPRequest>MACROS,%FILEEXEC%,GET,,salvar
            
      IfFileExists>%FILEEXEC%
        Include>%FILEEXEC%
        //ExecuteFile>%FILEEXEC%
        Wait>8
        DeleteFile>%FILEEXEC%
      ENDIF
            
      SRT>MyErrs
        Msg>LAST_ERROR
        Let>ONERROR=donothing
        Let>IGNOREERRORS=1
              
        Let>IGNOREERRORS=0
        Let>ONERROR=MyErrs

      END>MyErrs
      SRT>donothing
        //dummy error handler when we want to do nothing and ignore
      END>donothing
      IF>LAST_ERROR<>
        Let>ST=99
      ELSE
        Let>ST=2
      ENDIF
      Let>lin=lin+1
      Wait>10
    ELSE
      Let>lin=10
    ENDIF
  Until>lin=10
ENDIF

User avatar
Marcus Tettmar
Site Admin
Posts: 7380
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: Run downloaded macros and collect execution

Post by Marcus Tettmar » Thu Jul 16, 2020 2:08 pm

Use the Macro command and set MACRO_RESULT:

https://www.mjtnet.com/manuals/v15/HTML/macro.html
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

thiagunix
Junior Coder
Posts: 23
Joined: Tue May 05, 2020 2:16 pm

Re: Run downloaded macros and collect execution

Post by thiagunix » Thu Jul 16, 2020 6:59 pm

Hello,

I tried that. MACRO_RESULT always returns empty.

Code: Select all

Macro>%FILEEXEC%
MessageModal>%MACRO_RESULT%
Thanks

User avatar
Marcus Tettmar
Site Admin
Posts: 7380
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: Run downloaded macros and collect execution

Post by Marcus Tettmar » Fri Jul 17, 2020 7:33 am

It works for me:

Called_Macro.scp:
----
Let>MACRO_RESULT=HELLO

Calling Macro:
----
Macro>%SCRIPT_DIR%\Called_Macro.scp
MessageModal>MACRO_RESULT

When I run calling macro it displays 'Hello' in the message box.

Which version of Macro Scheduler are you using?
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

thiagunix
Junior Coder
Posts: 23
Joined: Tue May 05, 2020 2:16 pm

Re: Run downloaded macros and collect execution

Post by thiagunix » Fri Jul 17, 2020 2:14 pm

I'm using version 15.0.09.

I did the same test you mentioned using the debug to test and I can see when it goes through the line
Let> MACRO_RESULT = Hello
it sets the hello value

however when he executes
Macro>% FILEEXEC%

he reset MACRO_RESULT
and returns empty.

Then I was in doubt

Thanks

User avatar
Marcus Tettmar
Site Admin
Posts: 7380
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: Run downloaded macros and collect execution

Post by Marcus Tettmar » Fri Jul 17, 2020 3:19 pm

Can you try again without the spaces?
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

thiagunix
Junior Coder
Posts: 23
Joined: Tue May 05, 2020 2:16 pm

Re: Run downloaded macros and collect execution

Post by thiagunix » Fri Jul 17, 2020 3:52 pm

I did and keeps coming back empty.

Code: Select all

Let>MACRO_RESULT=Hello
Macro>%TEMP_DIR%mje_temp.scp
MessageModal>%MACRO_RESULT%
Just to illustrate my problem.

To test it it downloads a macro that has an error
let>a=1/0 // Macro code downloaded
and returns empty

in the sequence it downloads another macro without error
let>a=10/2 // Macro code downloaded
and in the same way it returns empty.

User avatar
Marcus Tettmar
Site Admin
Posts: 7380
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: Run downloaded macros and collect execution

Post by Marcus Tettmar » Fri Jul 17, 2020 4:03 pm

You are not following me. You need to set MACRO_RESULT in the *CALLED* macro. Please see again my example:

Code: Select all

Called_Macro.scp:
----
Let>MACRO_RESULT=HELLO

Calling Macro:
----
Macro>%SCRIPT_DIR%\Called_Macro.scp
MessageModal>MACRO_RESULT
E.g.

1. Create a new macro. Call it e.g. MACRO_B.
2.Add this line in it:
Let>MACRO_RESULT=HELLO.
3. Save it.
4. Create another macro. Call it MACRO_A.
5. Add these lines:
Macro>%SCRIPT_DIR%\MACRO_B.SCP
MessageModal>MACRO_RESULT
6. Save it.
7. Run MACRO_A.
8. You should see "HELLO" appear in the message.

So basically any macro you *CALL* can set MACRO_RESULT to ANYTHING. Then after using the Macro command to *CALL THAT MACRO* you will have a copy of MACRO_RESULT.

What you are finding is that MACRO_RESULT is being RESET by the macro you are calling. To nothing. Because you have not set it IN THE CALLED MACRO.

I am really not sure how to be more clear here. It is stated in the help file. I have provided a simple example. I hope this reply makes it more clear.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

User avatar
Grovkillen
Automation Wizard
Posts: 1021
Joined: Fri Aug 10, 2012 2:38 pm
Location: Bräcke, Sweden
Contact:

Re: Run downloaded macros and collect execution

Post by Grovkillen » Fri Jul 17, 2020 5:40 pm

I understand you Marcus, so it's not you ;)
Let>ME=%Script%

Running: 15.0.24
version history

thiagunix
Junior Coder
Posts: 23
Joined: Tue May 05, 2020 2:16 pm

Re: Run downloaded macros and collect execution

Post by thiagunix » Tue Jul 21, 2020 4:06 pm

There is no way to be clearer than that.

For my demand it is not enough. :(

I need to run other macros and collect the status of the run if it ran or gave an error.

I will continue to search. Likewise thanks for the help.

User avatar
Marcus Tettmar
Site Admin
Posts: 7380
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: Run downloaded macros and collect execution

Post by Marcus Tettmar » Tue Jul 21, 2020 5:10 pm

I need to run other macros and collect the status of the run if it ran or gave an error.
So create a custom error handler in the called macro. If an error occurs, set MACRO_RESULT accordingly. Test for any other specific issues that may occur when automating your target app and set MACRO_RESULT accordingly. Etc etc.

The point is you can create whatever conditional logic you need, and check for whatever external events you need to check for, and as long as you set MACRO_RESULT to something you will have access to this in the calling macro.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts