Text Manipulation

Often your configurator will need to manipulate a block of text. It could be for an informative message in a Validation Rule, assembly instructions or legal text in an Output Document, or even part of a dynamic HTML element or SVG image within your configurator as it runs on-screen.  Here are some suggestions for the best ways to get the text strings you want with Snap.

Concatenate

The concatenate block will make one larger string from two or more smaller ones.  It's similar to "adding" strings together, so it looks very similar to the math block.  It can be mutated to have as many slots as you need. 

Replace

The replace block will replace every occurrence of a substring with the replacement text you specify. Replacements can be either simple text replacement, or more powerful regex replacements.

Example use (simple text):

Format Text

The Format Text function is an even more powerful way to replace text.  It will replace only blocks of text that 1) are "tagged" with a special code, and 2) are spelled exactly the same as some element of a data structure you give it.  Called string interpolation, this technique allows you to manipulate large, complex strings easily.

The "tag" used to mark text you want to replace is ${ before the text, and } after it.

Example uses: 

  1. Here, we create a map of key/value pairs.  By passing that map into the format text function, any tagged text that matches any element key in our map is replaced with that element's value.


  2. You're not limited to simple maps.  Format text also accepts any standard type built in to Epicor CPQ, or even a custom type you design.  In this next example, we declare a custom type and then create a new variable of that type called "obj".  By simply passing that "obj" variable into the format text block, we get back the original string, but with all the tagged text replaced with the corresponding values.



Was this article helpful?