Pimberly supports a number of functions and constants which can be used in expressions in assignment rules, workflows, feeds and channels. These functions are described below.
Note you can also normally combine functions in one attribute, for example {productName|replaceAll _ -|upperCase}
will replace all underscores with hyphens and then convert the result to uppercase.
Functions
attrKey attributeName
Returns a key value from a key-value pair attribute, where the name of the key to lookup is stored in attributeName.
{productSpecs|attrKey keyLookup}
e.g. Given a plain text attribute keyLookup and the KVP attribute productSpecs with keys brand
and description
:
"productSpecs": { "brand": "Acme, Inc.", "description": "Heavyweight anvil" }
Setting the value of keyLookup to brand
would cause the expression to return the value Acme, Inc.
. Changing the value in keyLookup to description
would cause the expression to return Heavyweight anvil
.
See also: key.
capitalise
Converts the first character in the string to upper case.
{productName|capitalise}
e.g. Given the string men's t-shirt
in the attribute productName, outputs the string Men's t-shirt
.
See also: lowerCase, titleCase, upperCase.
char
Converts the input value (a base-10 number) to its Unicode equivalent.
{characterDigit|char}
e.g. Given the value 72
in the attribute characterDigit, outputs the value H
; given the value 8253
, outputs the interrobang character ‽
.
See also: code.
checkdigit
Returns the attribute value with a mod10 (Luhn) check digit appended.
{shortCode|checkdigit}
For example, given an attribute shortCode with value 234567
, will return the string 2345676
.
Can be combined with padStart to generate a fixed-length string with a check digit:
{shortCode|checkdigit|padStart 10 0}
For example, given an attribute shortCode with value 234567
, will return 0002345676
.
clean
{productName|clean}
Removes any character except the following from a string:
- The space character
- Symbols
!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~
- Numerals
0123456789
- Uppercase characters
ABCDEFGHIJKLMNOPQRSTUVWXYZ
- Lowercase characters
abcdefghijklmnopqrstuvwxyz
Technically speaking, any characters outside the ASCII range 32-126 will be removed, for example, line breaks, accented characters and invisible control characters.
See also: stripNonAlNum.
code
Returns the numeric (base-10) value of the first character in the given string.
{productName|code}
e.g. Given the string Men's t-shirt
in the attribute productName, outputs the value 77
.
See also: char.
dataSetLookup dataSetIdfromColumn>toColumn
Using the specified data set, looks up the attribute value in the fromColumn and returns the value in the toColumn.
Note that there is no space between dataSetId and fromColumn, and a greater-than sign is used to separate fromColumn and toColumn.
{colour|dataSetLookup 5e18898b6884a300179ae657Colour_EN>Colour_NL}
e.g. Given a colour attribute containing the value White
, and the following data set with ID 5e18898b6884a300179ae657:
Colour_EN | Colour_NL | Colour_FR |
---|---|---|
Black | Zwart | Noir |
Green | Groen | Vert |
White | Wit | Blanc |
The function would return the value Wit
.
Tips:
- Note that columns are referred to by name, not position, so make sure that updates to data sets (e.g. from file) do not change the column headings - otherwise, your data set lookup will no longer work.
- To obtain the data set ID, view the data set in Pimberly and retrieve the ID from the end of the page URL.
- If you are using a True or False attribute as the lookup value in the dataset, use the values "true" and "false" as your data set values, rather than "0" and "1" or "yes" and "no".
dateAdd units number
Add or subtract the specified number of periods defined by units to a date attribute.
Use a positive value for number to add periods; use a negative value to subtract periods.
units can be any one of: day
, week
, month
, year
.
{productDate|dateAdd day 1}
e.g. given a date attribute called productDate set to 2023-08-03T00:00:00.000Z
, returns the value 2023-08-04T00:00:00.000Z
.
find findValue
Returns the character position of the first character in findValue, where position 0 is the first character in the string.
{productName|find shirt}
e.g. Given the string Men's T-shirt
in the attribute productName, outputs the value 8
.
getTime
Given a date or date and time attribute, returns the number of milliseconds since 1 January 1970 (the Unix epoch).
{dateTime|getTime}
This can be used to calculate the number of days between two dates:
{endDate|getTime}-{startDate|getTime}
Divide the result by 86,400,000 to convert the value from milliseconds to days. You can then use toFixed to round the result to whole days.
gtincheckdigit
Returns the attribute value with a GS1-compliant check digit appended. Use in conjunction with company prefix and product number attributes to generate a UPC barcode.
{companyPrefixAndProductNumber|gtincheckdigit}
e.g. Given an attribute companyPrefixAndProductNumber with value 01234567890
, will return the string 012345678905
.
Can be combined with padStart to generate a fixed-length string with a check digit as described above.
key keyName
Returns the value of the key keyName from the specified key-value pair (KVP) attribute.
{productSpecs|key brand}
e.g. Given the KVP attribute productSpecs with keys brand
and description
:
"productSpecs": { "brand": "Acme, Inc.", "description": "Heavyweight anvil" }
Setting the value of key to brand
would cause the expression to return the value Acme, Inc.
.
See also: attrKey.
locale localeId
Returns the value of the attribute in the given localeId.
{productName|locale 5c7f9b48714ab8000fd83df1}
e.g. Returns the value of productName in the specified locale.
Can be combined with other functions, including scope, where required.
length
Return the length of the string.
{productName|length}
e.g. Given the string Men's T-shirt
in the attribute productName, outputs the value 13
.
lowerCase
Converts a string to lower case.
{productName|lowerCase}
e.g. Given the string Men's T-shirt
in the attribute productName, outputs the string men's t-shirt
.
See also: capitalise, titleCase, upperCase.
padStart length numeral
Pads the value of the attribute to the specified length with the given numeral, at the beginning of the string.
length: The length of the resulting string once the initial string has been padded
numeral: The numeral with which to pad the string.
{shortCode|padStart 10 0}
For example, given an attribute shortCode with value 12345
, returns 0000012345
.
replace searchValue replaceValue
Replaces the first occurrence of searchValue with the value of replaceValue.
{productName|replace T-shirt Sweatshirt}
e.g. Given the string Men's T-shirt, Joggers and T-shirt
in the attribute productName, outputs the string Men's Sweatshirt, Joggers and T-shirt
.
Notes:
Certain characters need to be escaped, either with a backslash or with their UTF-8 hexadecimal equivalent when used in the search parameter:
- For
.
use\.
or\x2e
- For space, use
\x20
- For
(
use\x28
- For
)
use\x29
You can chain multiple replace expressions together, e.g. replace _ -|replace \. -
will replace the first underscore and the first dot with a hyphen.
replaceAll searchValue replaceValue
Replaces all occurrences of searchValue with the value of replaceValue.
{productName|replaceAll T-shirt Sweatshirt}
e.g. Given the string Men's T-shirt, Joggers and T-shirt
in the attribute productName, outputs the string Men's Sweatshirt, Joggers and Sweatshirt
.
Notes:
- See above for notes on replacing dots and spaces.
scope scopeId
Returns the value of the attribute in the given scope.
scopeId: Either *
for the master scope, or the ID of the required scope.
{productName|scope *}
e.g. Return the value of productName in the master scope.
Can be combined with other functions, including locale, where required. For example, {productName|scope *|upperCase}
returns the value of productName in the master scope, in upper case.
size
Returns the number of elements in an array-type object such as a media set, product set, multi-select or free-typed list.
{productImages|size}
e.g. Given a media set attribute called productImages containing 3 assets, returns 3
.
NB: Multi-valued attributes cannot be selected in the attribute picker, so users will need to type the short name of the attribute into the expression editor manually.
slice startPos [endPos]
Extracts a section of a string.
startPos: the position where extraction should begin. 0 indicates the beginning of the string.
endPos: (optional) the position before which to end extraction. The character at this position will not be included. If omitted, extraction continues to the end of the string.
Negative numbers offset the start or end position by the specified number of characters.
Examples
- Remove the last character from the string:
slice 0 -1
- Remove the first character from the string:
slice 1
- Remove everything except the last character:
slice -1
In detail: given the string Men's T-shirt
in the attribute productName:
-
{productName|slice 0 5}
returnsMen's
-
{productName|slice 0 1}
returnsM
-
{productName|slice 0 -5}
returnsMen's T-
-
{productName|slice -7 -3}
returnsT-sh
-
{productName|slice 6}
returnsT-shirt
(i.e. from the "T" to the end of the string) -
{productName|slice -5}
returnsshirt
(i.e. from 5 characters from the end, to the end of the string)
split start
Removes the number of characters specified in start from the beginning of the string.
{productName|split 6}
e.g. Given the string Men's T-shirt
in the attribute productName, outputs the string T-shirt
.
NB: This is equivalent to using the slice function without a second parameter, i.e. {productName|slice 6}
.
splitDelim delimiter L/R
Splits a string into two parts based on the first instance a delimiter character. Use L or R to determine which of the two split values you want to retain. Does not retain the delimiter character.
{productColour|splitDelim , L}
e.g. Given the string red,blue
in the attribute productColour, returns red
.
{productColour|splitDelim , R}
e.g. Given the string red,blue
in the attribute productColour, returns blue
.
splitDigit L/R
Splits a string into two parts based on the first character change from digit to non-digit character. Use L or R to determine which of the two split values you want to retain.
{productName|splitDigit L}
e.g. Given the string 100 percent cotton
in the attribute productName, returns 100
.
{productName|splitDigit R}
e.g. Given the string 100 percent cotton
in the attribute productName, returns percent cotton
. Note the space at the beginning of the string.
splitLeft number L/R
Splits a string into two parts based on the number of characters from the start (left) of the string. Use L or R to determine which of the two split values you want to retain.
{productName|splitLeft 5 L}
e.g. Given the string Men's T-shirt
in the attribute productName, returns Men's
.
{productName|splitLeft 5 R}
e.g. Given the string Men's T-shirt
in the attribute productName, returns T-shirt
. Note the space at the beginning of the string.
splitLower L/R
Splits a string into two parts based on the first instance of a change from lowercase to uppercase. Use L or R to determine which of the two split values you want to retain. Does not retain the delimiter character.
{productName|splitLower L}
e.g. Given the string macOS
in the attribute productName, returns mac
.
{productName|splitLower R}
e.g. Given the string macOS
in the attribute productName, returns OS
.
splitRight number L/R
Splits a string into two parts based on the number of characters from the end (right) of the string. Use L or R to determine which of the two split values you want to retain.
{productName|splitRight 5 L}
e.g. Given the string Men's T-shirt
in the attribute productName, returns Men's T-
.
{productName|splitRight 5 R}
e.g. Given the string Men's T-shirt
in the attribute productName, returns shirt
.
splitUpper L/R
Splits a string into two parts based on the first instance of a change from uppercase to lowercase. Use L or R to determine which of the two split values you want to retain. Does not retain the delimiter character.
{productName|splitUpper L}
e.g. Given the string ACMEproduct
in the attribute productName, returns ACME
.
{productName|splitUpper R}
e.g. Given the string ACMEproduct
in the attribute productName, returns product
.
stripNonAlNum
Returns the attribute value with non-alphanumeric (characters not in the set [A-Za-z0-9]
) removed. Note that accented characters such as é
will be removed.
{stockCode|stripNonAlNum}
e.g. Given an attribute stockCode with value ABC-123
, returns the string ABC123
.
Can be combined with other functions, for example with upperCase
to change the case of the result.
See also: clean.
substitute start end replace
Substitute a subsection of the attribute value with new text.
{productName|substitute 1 5 Unisex}
e.g. Given the string Men's T-shirt
in the attribute productName, outputs the value Unisex T-shirt
.
titleCase
Converts the string to to title case. The first letter of certain words such as "and" and "the" will not be capitalised if they appear within the string.
{productName|titleCase}
e.g. Given the string men's t-shirt and joggers bundle
in the attribute productName, outputs the value Men's T-Shirt and Joggers Bundle
.
NB: Words entirely in upper case will be ignored.
See also: capitalise, lowerCase, upperCase.
toFixed accuracy
Returns a number to the specified number of decimal places. Note that values will be rounded and padded.
{productPrice|toFixed 2}
e.g. Given the value 2.344
in the attribute productPrice, outputs the value 2.34
. The value 2.345
would be rounded to 2.35
. The value 2.3
would be padded to 2.30
.
upperCase
Converts a string to upper case.
{productName|upperCase}
e.g. Given the string Men's T-shirt
in the attribute productName, outputs the string MEN'S T-SHIRT
.
See also: capitalise, lowerCase, titleCase.
Constants
The expression editor supports the following constants:
-
{_CURRENT_USER_EMAIL_}
Outputs the email address of the current user. -
{_CURRENT_USER_FULLNAME_}
Outputs the full name of the current user. -
{_FILENAME_}
When used in a rename expression of a media set mapping in a channel, returns the original filename of the asset. -
{_FILE_EXTENSION_}
When used in a rename expression of a media set mapping in a channel, returns the file extension from the original filename. -
{_NOW_}
Returns the current date and time. -
{_TODAY_}
Returns the current date.
Operators
Concatenating string values
{productCode}+" "+{productDescription}
String values can be concatenated using the +
operator. For example, for a product with a productCode of AB123
and a productDescription of Acme Widget
, return the string AB123 Acme Widget
.
Arithmetic operations
Simple arithmetic operations for addition, subtraction, multiplication, division and exponentiation (+
, -
, *
, /
and **
respectively) can be applied to numeric attributes.
Logical OR
The logical OR operator ||
can be used to return the first non-null value in a list of expressions.
For example, given a product with a Specific Colour of "Apple red" and a Generic Colour of "Red", the following expression would output "Apple Red". If Specific Colour was blank, the expression would output "Red".
{specificColour}||{genericColour}
A string can be used in place of an attribute reference. This can be useful if you want the expression to output a fixed value if the desired attribute has no value.
{specificColour}||{genericColour}||"No colour specified"
In the example above, if neither Specific Colour nor Generic Colour are defined on the product, then the expression would output "No colour specified".