Customer Portal

2 x replace functions in one entry?

Comments 2

  • Avatar
    the_goat
    0
    Comment actions Permalink
    In this trivial case, I'd use switch statement instead:

    switch($in.0.Sex){
    case "f":
    case "F":
    $out.0.Sex = "Female";
    break;
    case "m":
    case "M":
    $out.0.Sex = "Male";
    break;
    default:
    $out.0.Sex = null;
    }


    More elegant way, where you might have more "translation" could involve SimpleLookup.
    Nevertheless, I'm wondering how rest of your code looks like. Because what you describe should not happen.
  • Avatar
    Vladimir Barton
    0
    Comment actions Permalink
    Hi all,
    thank you for the question as well as the answer. Using the ‘switch’ statement is indeed one of the possible options how to deal with such replacement.
    If you want to stick to the ‘replace’ statement that you demonstrated in your issue description, you could also use the following piece of CTL code in the Reformat component:

    $out.0.Sex = replace(replace($in.0.Sex,"[mM]","Male"),"[fF]","Female");

    Note: this example will work in your particular situation with the “Male” and “Female” string, however, it is not generic. There are a handful of more generic approaches such as already mentioned ‘switch’ statement and ‘SimpleLookup’, also ‘if’ statement or some of the other lookups could be used for this purpose in general.

Please sign in to leave a comment.