Question
Werner Beukes · Jan 20, 2021

String manipulation on a field during transformation using a ClassMethod.

I need to do some nifty string manipulation on a source property. I will not be able to do it with the functions available(with the knowledge that I have of what is available). Could I call a ClassMethod to do this for me? This is what I want to do: The source property is "myemail@myemaildomain.co.uk". I need to add the text "test" to the beginning of that string. "testmyemail@myemaildomain.co.uk". That should be simple enough, but then I have to do this as well, "testmyemail@myemaildomaintest.co.uk". Note the additional "test" added after "myemaildomain".

0
0 173
Discussion (7)1
Log in or sign up to continue

I'm assuming you're working with Ensemble (or Interoperability as it's known in the most recent IRIS-based versions) ...

If you create a class that extends Ens.Rule.FunctionSet, not only will you be able to call its methods/functions from the DTL editor, they will appear as selectable functions in the drop-down list.

Now why did I not think of that? Perfect answer, thanks. 

Hey Werner.

I know I have ignored your request on how to call a class method (Jeffery has you covered by the looks of things), but you could use $PIECE to break the string apart and then insert what you need.

For example if "source.{PhoneNumberHome(1).Emailaddress}" is equal to "myemail@myemaildomain.co.uk" then 

"test"_$PIECE(source.{PhoneNumberHome(1).Emailaddress},".",1)_"test"_"."_$PIECE(source.{PhoneNumberHome(1).Emailaddress},".",2,*)

will return: 

"testmyemail@myemaildomaintest.co.uk"

The idea being that we

  • Start the new string with "test"
  • take everything before the first period with $P(source.{PhoneNumberHome(1).Emailaddress},"."1) 
  • Add "test" in again
  • Add a period that gets dropped from the $PIECE from using the period as the delimiter
  • Provide everything from the second period onwards with $P(source.{PhoneNumberHome(1).Emailaddress},".",2,*)

That is the alternative, but I thought it would be "nice" to have another option and you gave it to me. Now I can impress my peers.

Julian. Your answer makes the solution compete. I just put in the Method that was created in Ens.Rule.FunctionSet with a few minor changes and Bob's your uncle.

Edit: Oops... I see Jeff Drumm already nailed this!

The best way to do this is to define your own custom utility function (which is just a class method). Your custom function will then appear in the function list in the DTL editor along side the standard functions.