Automation
Automation

Scripting How-To: Tracking the Failure or Success of a SLAX Script with Variables

by Administrator Administrator on ‎03-30-2016 02:20 PM - edited on ‎08-23-2017 11:31 AM by Administrator Administrator
03.30.16   |   02:20 PM

To track the failure or success of a SLAX script, you typically look through several blocks of XML. If a certain value exists in one of more of the blocks, run a "success" block of code; otherwise, run a "failure" block of code. This would be trivial if the SLAX script had variables that you could modify, but it does not. So one solution is to feed back XML data into a variable while you process the XML document, and then check that variable afterward.

 

For example:

 

var $catch-results := {
    for-each( $configuration/interfaces/interface ) {
        if( mtu == "1500" ) {
            <error> "Bad MTU";
        }
        else {
            <success>;
        }
    }
}
 
if( $catch-results/error ) {
    expr jcs:output( "There was an error");
}