EZ Exporter Calculated Fields - Text Operations

Text operations let you manipulate text fields in your report.

AVAILABLE OPERATORS

  • +, Combines text (e.g. {{ text_field }} + "hello", {{ text_field1 }} + {{ text_field2 }}).
  • [], Slice part of the text (gives the character from a given index, e.g. if the value of a text_field is "hello", {{ text_field }}[1] will give "e", note that the index count starts at 0).
  • [:], Range slice (gives the characters from a given range, e.g. if the value of text_field is "hello", {{ text_field }}[1:4] will give "ell", note that the index count starts at 0 and the ending index is exclusive. You can also count backwards, for example {{ text_field }}[-3:] will give the last 3 characters "llo").
  • {{ text_field }}.replace("text_to_replace", "new_text"), Replace part of the text with new text.
  • {{ text_field }}.upper(), Converts the entire text to uppercase.
  • {{ text_field }}.lower(), Converts the entire text to lowercase.
  • {{ text_field }}.split(","), Splits the text by the comma separator (you can specify a different separator).
  • {{ text_field }}.strip(), Removes leading and trailing characters (by default, it will remove leading and trailing space characters, you can specify the characters inside the function like strip("abc")).
  • str({{ number_field }}).replace(".", ","), Converts a number field into text/string so you can perform text operations on it.

EXAMPLES

Remove parentheses and dashes in the shipping phone number.

{{ shipping_address.phone }}.replace("(", "").replace(")", "").replace("-", "")

I want a field of the product title all in capital letters.

{{ line_items.title }}.upper()

I want a field of just the first five letters of the SKU (note that the index starts at 0) and add the text "snipped" to it.

{{ line_items.sku }}[0:5] + "snipped"

Remove all leading and trailing spaces from the data.

{{ line_items.title }}.strip()

To remove leading and trailing dashes instead:

{{ line_items.title }}.strip("-")

Split the text by the "-" character and return the first element, removing leading and trailing spaces at the same time.

If the product title is: "Red Shorts - Special Edition - Extra Large"

The formula:

{{ title }}.split("-")[0].strip()

Will return: "Red Shorts"

To return the 3rd element instead after splitting the text:

{{ title }}.split("-")[2].strip()

Will return: "Extra Large"

NOTES

Please note that these can only be applied to "text-type" fields. If you'd like to use text operations on "number-type" fields such as IDs and prices, please convert them to text first by simply enclosing the variables with quotes like this:

"{{ customer.id }}"[1:5]

Or use the str() function like this:

str({{ customer.id }})[1:5]

App: EZ Exporter

Tags: advanced features