Transformation Types

Summary

Overview

  • Transformations can be chained
  • SDM doesn’t handle calculations (Ex: we don’t calculate the TVA from the prices columns)

Types of Transformations

Transformation Parameters Description Example
Capitalize which (start, sentences, word, all, none) Capitalizes specific parts of a text based on the which parameter.  start: First character only
sentences: First character. Of each! Sentence (.?!)
word: First Character Of Each Word
all: ALL CHARACTERS
none: all lowercase
  mode (strict, loose) Defines how strict or loose the capitalization should be. Strict: The Sdm App Is Awesome
Loose: The SDM App Is Awesome
trim_whitespaces multiple Removes spaces at the beginning and end of a text string. If multiple is True, reduces multiple space characters between words to a single space character. Input: " Hello World " 
Output: 
"Hello World"
With 
multiple :
Input: 
" I am John" 
Output: 
"I am John"
regex pattern (string) Defines what needs to be transformed  
  substitution (string) Specifies the substitution text to replace the matched pattern.  
  force True/False If true: SDM empties the value
If false but the value doesn’t match, nothing happens
 
pad pad_character, pad_length Adds characters to the left or right of the string to reach a specific length. Example: EAN exported from Excel like this 0003542147089. The first 3 zeros will not be imported, resulting in an invalid EAN. Setting pad_character to 0 and pad_length to the EAN length will prepend with the missing 0s.

1. Capitalize

Adjusts the capitalization of text values.

Parameters:

  • name: capitalize
  • which: Determines what to capitalize. Options:
    • "start": Capitalizes only the first character.
    • "sentences": Capitalizes the first character of each sentence (default).
    • "words": Capitalizes the first character of each word.
    • "all": Converts the entire string to uppercase.
    • "none": Converts the entire string to lowercase.
  • mode: Determines the strictness of capitalization. Options:
    • "strict": Uses Python's built-in capitalize() method.
    • "loose": Only capitalizes the first character, leaving the rest unchanged (default).

Example:

> "hello world. how are you?" # (which="sentences", mode="loose")
# Output: "Hello world. How are you?" 

2. Trim Whitespaces

Removes excess whitespace from the value.

Function: trim_whitespaces(value, multiple=False)

Parameters:

  • name: trim_whitespace
  • multiple: If True, replaces all multiple spaces within the string. If False only the extra spaces at the start and end of the string are replaced.

Example:

> "  Hello   world!  " # (multiple=true)
# Output: "Hello world!"

3. Regex

Applies a regular expression substitution to the value.

Parameters:

  • name: regex
  • pattern: The regex pattern to match.
  • substitution: The string to replace matched patterns with.
  • flags: List of regex flags to use. Options: "ascii", "multiline", "ignorecase", "dotall". Uses Python flags behind the scenes.
  • force: If True, returns None when the pattern doesn't match.

Example:

> "Hello123World" # (pattern=r"\\\\d+", substitution="", flags=["ignorecase"])
# Output: "HelloWorld"

4. Pad

Pads the string value to a specified length.

Parameters:

  • name: pad
  • fill: The character to use for padding.
  • direction: Where to add padding. Options: "left" or "right".
  • length: The desired total length of the string after padding.

Example:

> "123" # (fill="0", direction="left", length=5)
# Output: "00123"

Usage Notes

  • Transformations run on all the fields sent to the step. During the step, when the user modifies a field in the UI, the transformation will only run on the fields that have been modified after the form has been submitted.
  • Transformations are applied in the order they are specified in the configuration.