SplitString-Function RRS feed

  • Question

  • FYI for the SplitString Function:

    I was getting the following error:

    "The function 'SplitString' is improperly formatted or is missing a required parameter. Execution mode: Resolve."

    This was because I was trying to use the function in a scenario where the first parameter (input:string) was sometimes null, //Target/Value] in the example below:

    eg: SplitString([//Target/Value],$delimiter)

    I found this error was still true if I placed the SplitString function inside an IIF statement, eg:


    This is because the code resolves the statements and tests for nulls before evaluating the functions outputs.

    I found the follow workaround worked well for me:


    This causes the first parameter (input:string) to always resolve to a string and so remove the error, but when fed a null via [//Target/Value] the output is still a empty list (or at least a list with only one "" in it), and when fed a non-null via [//Target/Value] the output is processed as expected.

    @Nilesh Ghodekar could we add something regarding the above to the SplitString-Function page? ( )

    Monday, April 9, 2018 4:25 AM

All replies

  • Thanks Michael for reporting the issue and documenting the work-around. Right now, the function behaves as is documented in the Wiki, so I'll take this as a design change request to allow null values in this function. Probably, it will also be worth taking a look at other functions as well as they'll all behave the same way. It make sense to make these changes to have a more sensible treatment of the null values.

    Monday, April 9, 2018 9:47 AM
  • Thanks Nilesh :)
    Tuesday, April 10, 2018 6:09 AM
  • Just for clarity, when I said "..they'll all behave the same way...", I meant that, if they are documented to throw an exception on null input, they all with throw an exception and a common workaround for all of them is do a null check on the the input and pass in a sensible default if you expect a null value can be passed. So in your example, you could write SplitString( IIF(IsPresent([//Target/Value]),[//Target/Value],"DefaultTargetValue"), $delimiter). But like I said, there is opportunity to get rid of null check in a few more remaining functions.
    Tuesday, April 10, 2018 6:33 PM
  • Thanks Nilesh; makes sense.

    I hadn't considered putting the IFF inside the SplitString; that is a clearer workaround.

    I look forward to the removal of the null check as with the current setup I don't believe there is an easy way to hand a Null or empty List<string> using the SplitString function?  Or does the following achieve that:

    SplitString( IIF(IsPresent([//Target/Value]),[//Target/Value],$delimiter), $delimiter )

    Thanks again!

    Wednesday, April 11, 2018 12:36 AM
  • Both your original workaround and this one will lead to the same result. A list object with Count=0. Would like to know where would you care if the return value is null vs a list object with item count = 0?
    Wednesday, April 11, 2018 8:30 AM
  • Ah okay, thanks for clearning that up :)

    I haven't found a situation where I care whether the value returned is null vs an empty list count; and I suppose if one did you could just wrap it in an IIF and have that push out the null (assuming you could test for an empty list).

    Wednesday, April 11, 2018 12:37 PM