Kaseya Community

stop procedure if condition is true

  • Is there a way to stop an agent procedure when a condition is true.

    Ive build a script which checks some registry keys. If a key exists the script will start an another procedure. After starting the script this main procedure should stop.

  • There's no specific "break" function in the scripting engine.

    I set a variable called global:stopThePresses to False at the beginning of the script.  If I encounter a situation that dictates that I should stop the script, set global:stopThePresses to True.

    I then put If (#global:stopThePresses# is not equal to True) Then [continue the rest of the procedure]...

    Simple, but works (in lieu of a proper break function).

  • I like Brian's way better, but here's mine: Get Variable step... File Content of "C:\ShouldNotExist.xxx" ---> IntentionalFail.

  • As above there are really only 2 ways to do it . One is force the script to fail at the point you want it to stop , or set a variable that will indicate if you want to proceed to the next procedure and set this variable to "yes" "No" as you progress thru your script , then at the very end of your script test the variables value in an If/Then

    Paul

  • I pretty much do the same and I break my procedures in into two separate sections.

    Part 1 - Contains all the predefined variables and checks, initially creating Boolean a global variable called #global:ExecuteProcedureTask# and setting its value as FALSE. During the checks using an if statements, I check if all the conditions are met and change the #global:ExecuteProcedureTask# variable to TRUE.

    Part 2 - Contains the if statement that checks if the value of #global:ExecuteProcedureTask# is TRUE and if its not then it skips what ever the script was supposed to do.

    I also have two ways of forcing a failure or what I refer to as a synthetic failure.

    The quick and dirty method is to write a procedure log entry on why it failed and force the failure immediately when a check fails using the Get File Content called #ERROR# with the Value of ERROR

    Or the longer method I some times use by creating the #global:ERROR# variable in each check failure and specify the reason for each of the failure" as the value in Part 1 of my procedure but allowing the procedure to continue running all the checks.

    In the ELSE part of Part 2 I write a procedure log value and use the #global:ERROR# and after that I use the Get File Content called #ERROR# with the Value of ERROR to force the failure.