Check to see if result of a flow is null and if so, set it to a value.

Is there some method out of the box that would allow me to do the below?

 

Check to see if result of a flow is null and if so, set it to a value.

 

Thanks,

Don

 

  • Hello Don,

     

         The "String Equals" operation allows you to compare against empty values.

         Operation: /Library/Utility Operations/Math and Comparasion/String Equals

     

     

     

    <pre>
    Compares two strings, returning a true response if and only if they contain the same sequence of characters. A null string is considered to be equal to an empty string.
    
    Inputs:
    string1 - The first string.
    string2 - The second string.
    ignoreCase - If set to 'true', then the comparison ignores case considerations. The two strings are considered equal ignoring case if they are of the same length and corresponding characters in the two strings are equal ignoring case. If set to any value other than 'true', then the strings must match exactly to be considered equal.
    
    responses:
    true - If the two strings are equal
    false - If the two strings are not equal
    
    </pre>

     I hope this information help you to accomplish your task

  • Hi Don,

     

    There are a couple of ways you can do this.

     

    There is an operation in /lib/Utility Operations/Flow Variable Manipulation/Check Null that takes a variable name as input and has "is Null" "not Null" responses that can point to other operations.

     

    Alternatively if you want to make sure it always has a value you can either instanstiate it before hand in the flow, or you can handle it all within the result; add a filter to the result and choose type "Scriptlet". Set the body of the scriptlet to be:

     

    scriptletResult = (typeof scriptletInput == "undefined" || scriptletInput == null ? "" : scriptletInput);

     This will set the result to a zero-length string if the result is null or wasn't defined, otherwise it simply returns back what it got in. The above code is a conditional setting, it's equivalent in a If/Else is

     

    if (typeof scriptletInput == "undefined" || scriptletInput == null)
    {
      scriptletResult = "";
    }
    else
    {
      scriptletResult = scriptletInput;
    }

     If you are going to be using this approach a lot then you can create a new System Filter that developers can just drag into as a new Filter. You can do this in Studio by going to /Configuration/System Filters and Right Click -> Create New -> Scriptlet.

     

    Hope this helps.

     

    cheers

    steve

  • Steve,

     

    Thanks for the help!

     

    I had to modify a bit to work but you pointed me in the right direction.

     

    if (typeof scriptletInput == "undefined" || scriptletInput == null || scriptletInput == "")
    {
      scriptletResult = "All servers are OK.";
    }
    else
    {
      scriptletResult = scriptletInput;
    }

     

    Thanks!

    Don

     

  • Verified Answer

    Excellent, glad to hear you got it sorted. On the 'check null' operation in the library if you have a look at the scriptlet tab you can see it basically doing the same check (undefined, null and zero-length string).

     

    I personally don't treat zero-length as null but OO does.

     

    If that's helped do you mind marking it as the solution?

     

    cheers

    steve