MID
Use the MID function to extract a specified number of characters from a text value, starting at a given position.
Use
MID( text, start_num, num_chars )
Returns a specific number of characters from a text value starting at the given position.
| Parameter | Required | Description |
|---|---|---|
| text | Yes | the text containing characters to return |
| start_num | Yes | the position of the first character to extract (starting from 1) |
| num_chars | Yes | the number of characters to extract |
| Returns | Text |
Examples
Extracting a Sub-Code from a Project ID
In an Input Mapping Formula, you can use MID to isolate a specific segment of a structured text string captured in a previous step.
- Scenario: Your organization uses a project reference format like "PRJ-2024-LON" where characters 5 through 8 represent the fiscal year. You want to extract just the year to display it in a separate field on an approval form.
- Formula:
MID(@Trigger.out.ProjectReference, 5, 4) - Logic:
@Trigger.out.ProjectReference: The text string captured from the trigger form.5: The starting position (the 5th character, where "2" begins).4: The number of characters to extract (the four digits of the year).
- Result: If the reference is "PRJ-2024-LON", the function returns "2024".
Extracting Segments from Numeric Data
You can use MID to extract specific digits from numeric properties, such as a Run Number. However, because MID is a text function, you must first convert the number to text using the TEXT function.
- Scenario: You have a 5-digit employee ID number (e.g., 98765) where the middle two digits (76) represent a specific department code. You need to extract this code to use in a Path Condition Formula for a branch step.
- Formula:
MID(TEXT(@Trigger.out.EmployeeID), 3, 2) - Logic:
TEXT(@Trigger.out.EmployeeID): Converts the numeric ID into a Text data type soMIDcan process it.3: The starting position (the 3rd digit).2: The number of characters to extract.
- Result: If the ID is 98765, the function returns the text string "76".
Pro Tip: Always remember that the start_num and num_chars parameters must be Number values. If you attempt to use MID on an Array of text, the function will not work; you would first need to use an array function like INDEX or FIRST to isolate a single text string from the collection.