If any action in macro fails set variable to text?

I'm aware of the action result condition but I was curious if there was a better way than adding the action result condition after every single action in the macro.

Unfortunately there is no "try - catch" block for KM. But I have found that I rarely need to test each Action for failure. Usually I just let the Macro abort if the Action fails, which is the default option.

Why do you think you need to test for failure after EVERY Action in a Macro?
If you will upload your macro and provide us with your purpose/objectives, perhaps we can offer some suggestions.

If this isn't sufficient context I can upload the macro but it won't be repeatable as it operates within a login.

I have two Macros, Macro A and Macro B. Macro A performs a task once. Macro B executes Macro A multiple times in an until loop. TextToPaste is a variable that accumulates information. The Variable Loop Activity tells Macro A to not clear the TextToPaste variable if Macro B is operating.

Macro A starts with

If Variable "Loop Activity" is Active
    Do Nothing
Else
    Clear Variable TextToPaste

Macro B

Clear Variable Text To Paste
Set Variable Loop Activity to Active
Until Loop (
Execute Macro A
)
Set Variable Loop Activity to " "

The reason why I asked the original question is that Macro B resets the loop activity to inactive at the end if it completes successfully but if there an error any any point during the macro than that doesn't happen.

So If there's an error at anypoint and the macro is aborted I want the Variable Loop Activity to be reset to blank.

can Macro A send a success signal upon completion? If Macro B does not see a success signal then it assumes it was a fail?

Well, it is not clear which macro you are referring to, but assuming that Macro A is ONLY called from Macro B, and Macro B is your main Macro, I would do something this.

At the Top of Macro B

IF Variable MacroB_Success ≠ "DONE" THEN
   Set Variable Loop Activity to ""
END IF
Set Variable MacroB_Success to "FAILED"

At the Bottom of Macro B

SET Variable MacroB_Success to "DONE"

Adjust as needed for your other logic/data.

The should inform Macro B every time it is triggered whether or not it failed on the prior execution.

If you still need help, I will need to see the entire Macro B and Macro A (even if I can't execute them) in order to not waste any more of your or my time. There is a lot of ambiguity in your pseudo code and statements.

1 Like

Unfortunately, I do use Macro A outside of Macro B, which is the reason for the problem. If I perform Macro B and there's an error that prevents it from finishing, the loop activity incorrectly remains "active". Unless I manually go into preferences and change it back, If I try executing Macro A standalone , it won't clear the the TextToPaste variable.

Within Macro B i could exchange "Execute Macro A" with pasting the entire macro and removing the clear variable action, but solving this problem seemed like a better solution to reduce clutter.

Well, it is not clear which macro you are referring to

I originally meant both ( Macro B and Macro A inside Macro B ) but after reconsidering, in this case I don't believe there's anything that could go wrong with Macro B outside of "executing macro A" I could just use the action result condition and change the abort settings after the "execute Macro A".

If you still need help, I will need to see the entire Macro B and Macro A (even if I can't execute them)

Fair enough I will post the macros tomorrow when I get back to my mac, i sincerely appreciate your help.

I use the whole Macro A/B framework for a few different tasks, here's one of them.

"Copy Links" uses an incredibly primitive 'cntrl+f and found image' mechanism to copy 25 links from a page of search results. ( This was my solution for now, I did ask you in another thread about adapting your google search macro for linkedin)

"Copy Links Multi Page" does Macro A multiple times and loads the next page of search results.

I colored the relevant variable actions in magenta.

OK, I have reviewed your macros.

OK, but for the purpose of using Macro B to loop through all pages on a web site, and then call Macro A to extract the links on each page, it still seems to me that what I proposed above should work. Do you understand the logic I proposed above? Have you tried using it?

Macro B is the controlling macro. If an error occurs in it, OR when it calls Macro A, Macro B will abort. So the Variable MacroB_Success would still be "FAILED".
When you start (trigger) Macro B again, you can use that to decide how to handle the last error.

You're correct, after trying it, it works perfectly, I apologize I had originally misread your solution

Thank you once again for your help

1 Like