+
+

Building Formulas for Flows

Manipulate data in Composer by building expressions and applying functions. Using the Custom Expression Editor, create expressions that include functions and mathematical operators. Use the editor also to truncate words, capitalize phrases, and set the date.

When building formulas for a flow, keep in mind that:

  • You can nest functions and use the input parameters of another function call for your function.

  • Composer functions used in Composer are built using DataWeave.

  • Composer functions treat empty spaces as empty space characters in a formula.

String Functions

The Custom Expression Editor supports the following string formulas and operators:

Function Name Description Example Parameter Definition Input Data Type Parameters Output Data Type

lower

Returns the provided string in lowercase characters.

lower(COMPOSER) = composer

NA

text: String

String

upper

Returns the provided string in uppercase characters.

upper(composer) = COMPOSER

NA

text: String

String

capitalize

Capitalizes the first letter of each word in a string. This also removes underscores between words and puts a space before each capitalized word.

capitalize(name) = Name

capitalize(firstName) = First Name

capitalize(customer_first_name) = Customer First Name

NA

text: String

String

trim

Removes any blank spaces from the beginning and end of a string.

trim(<long example text>) = this example long text

NA

text: String

String

first

Returns the specified number of characters from the beginning of a string. If the number is equal to or greater than the number of characters in the string, the function returns the entire string.

first(Hello Composer!, 5) = Hello

NA

text: String

numCharacters: Number

String

last

Returns the specified number of characters from the end of a string.

last(Hello Composer!, 9) = Composer!

NA

text: String

numCharacters: Number

String

substitute

Replaces all substrings that match a literal search string with a specified replacement string. Replacement proceeds from the beginning of the string to the end. For example, the result of replacing aa with b in the string aaa is ba, rather than ab.

substitute(Composer, o, O) = COmpOser

substitute(Composer, a, Example) = Composer

NA

text: String

target: String

replacement: String

String

fromStringToBoolean

Transforms a string input value into a boolean value.

fromStringToBoolean(true) = true

fromStringToBoolean(FALSE) = false

fromStringToBoolean(TrUe) = true

NA

text: String

Boolean

fromStringToDate

Transforms a string input value into a date value. Accepts a format and locale. The format parameter represents the format of the input string.

The default format is uuuu-MM-dd and the default locale is en-US; however, these defaults can be modified.

fromStringToDate(2021-03-15, uuuu-MM-dd, en-US) = 2021-03-15

fromStringToDate(2021/15/03, uuuu/dd/MM, en-US) = 2021-03-15

Format: The format parameter represents the format of the input string. This parameter accepts Java character patterns based on ISO-8601. A Date value, such as 2011-12-03, has the format uuuu-MM-dd.

Locale: Optional ISO 3166 country code to use, such as en-US, AR, or ES.

text: String

format: String

locale: String

Date

fromStringToDateTime

Transforms a string input value into a dateTime value. Accepts a format and locale. The format parameter represents the format of the input string. The default format is uuuu-MM-dd’T’HH:mm:ss’Z and the default locale is en-US; however, these defaults can be modified.

fromStringToDateTime(2021-03-15T23:57:59Z, uuuu-MM-dd’T’HH:mm:ss’Z,US) = 2021-03-15T23:57:59Z

fromStringToDateTime(2021-03-15 23:57:59Z,uuuu-MM-dd HH:mm:ssz, en-US) = 2021-03-15T23:57:59Z

Format: The format parameter represents the format of the input string. This parameter accepts Java character patterns based on ISO-8601. A DateTime value, such as 2011-12-03T10:15:30.000000+01:00, has the format uuuu-MM-dd HH:mm:ssz.

Locale: Optional ISO 3166 country code to use, such as en-US, AR, or ES.

text: String

format: String
locale: String

DateTime

fromStringToNumber

Transforms a string input value into a number value.

fromStringToNumber(1) = 1

fromStringToNumber(0.05) = 0.05

NA

text: String

Number

It is important to note that in a string field, you can use number expressions selected from the operator list; however, the expressions must be enclosed within parentheses. For example, you can enter abc(9+9) where the + is selected from the operator list. This string renders as abc18.

Number Functions

In the Custom Expression Editor, a mathematical operator (+,-,*, or /) selected from the operator list is different from an operator typed and resolved as a string character. For example, the entry 9+9 is considered a string rather than 18. To use mathematical operators, select them from the operator list or use keyboard shortcuts.

The Custom Expression Editor supports the following number formulas and operators:

Function Name Description Example Parameter Definition Input Data Type Parameters Output Data Type

round

Rounds a number up or down to the nearest whole number.

round(1.2) = 1

round(4.6) = 5

round(3.5) = 4

NA

number: Number

Number

ceil

Rounds a number up to the nearest whole number.

ceil(1.2) = 2

ceil(3) = 3

NA

number: Number

Number

floor

Rounds a number down to the nearest whole number.

floor(2.2) = 2

floor(3) = 3

NA

number: Number

Number

abs

Returns the absolute value of a number.

abs(-3.4) = 3.4

abs(2) = 2

NA

number: Number

Number

fromNumberToString

Transforms a number value (whole or decimal) into a string value.

fromNumberToString(1) = 1

fromNumberToString(0.05) = 0.05

NA

number: Number

String

fromNumberToDateTime

Transforms a number input value into a dateTime value. Uses milliseconds or seconds as the unit. The default unit is seconds.

fromDateTimeToNumber(1443743879, seconds) = 2015-10-01T23:57:59Z

fromDateTimeToNumber(1443743879000, milliseconds) = 2015-10-01T23:57:59Z

Unit: The unit of time to use for the conversion: "milliseconds" or "seconds". The default unit is "seconds."

unit: String

DateTime

Date Functions

In the Custom Expression Editor, date and dateTime data pills can only be used as inputs. You cannot enter the dates manually.

The Custom Expression Editor supports the following date and dateTime formulas and operators:

Function Name Description Example Parameter Definition Input Data Type Parameters Output Data Type

today

Returns the date for today as a Date type.

today() = 2021-03-15

NA

NA

Date

now

Returns a DateTime value for the current date and time.

now() = 2021-03-15T18:23:20

NA

NA

DateTime

addDays

Creates and returns a Date value incremented or decremented by the specified number of days.

addDays(today(), 3) = 2021-03-18

addDays(2021-03-15, -4) = 2021-03-11

NA

date: Date

numDays: number

Date

addDays

Creates and returns a DateTime value incremented or decremented by the specified number of days.

addDays(now(), 3) = 2021-03-18T18:23:20

addDays(2021-03-15T18:23:20, 3) = 2021-03-18T18:23:20

NA

dateTime: DateTime

numDays: number

DateTime

addMonths

Creates and returns a Date value incremented or decremented by the specified number of months.

addMonths(today(), 3) = 2021-06-15

addMonths(2021-03-15, -4) = 2020-12-15

NA

date: Date

numMonths: number

Date

addMonths

Creates and returns a DateTime value incremented or decremented by the specified number of months.

addMonths(now(), 3) = 2021-06-15T18:23:20

addMonths(2021-03-15T18:23:20, -4) = 2020-12-15T18:23:20

NA

dateTime: DateTime

numMonths: number

DateTime

addYears

Creates and returns a Date value incremented or decremented by the specified number of years.

addYears(today(), 1) = 2022-03-15

addYears(2021-03-15, -1) = 2020-03-15

NA

date: Date

numYears: number

Date

addYears

Creates and returns a DateTime value incremented or decremented by the specified number of years.

addYears(now(), 3) = 2024-03-15T18:23:20

addYears(2021-03-15T18:23:20, -1) = 2020-03-15T18:23:20

NA

dateTime: DateTime

numYears: number

DateTime

addHours

Creates and returns a DateTime value incremented or decremented by the specified number of hours.

addHours(now(), 1) = 2021-03-15T23:23:20

addHours(2021-03-15T22:23:20, 3) = 2021-03-16T01:23:20

addHours(2021-03-15T22:23:20, -4) = 2021-03-15T18:23:20

NA

dateTime: DateTime

numHours: number

DateTime

addMinutes

Creates and returns a DateTime value incremented or decremented by the specified number of minutes.

addMinutes(now(), 5) = 2021-03-15T18:33:20

addMinutes(2021-03-15T23:45:00,15) = 2021-03-16T00:00:00

addMinutes(2021-03-15T18:23:20, -30) = 2021-03-15T17:53:20

NA

dateTime: DateTime

numMinutes: number

DateTime

addSeconds

Creates and returns a DateTime value incremented or decremented by the specified number of seconds.

addSeconds(now(), 30) = 2021-03-15T18:23:50

addSeconds(2021-03-15T23:45:00,15) = 2021-03-15T23:45:30

addSeconds(2021-03-15T18:23:20, -30) = 2021-03-15T18:22:50

NA

dateTime: DateTime

numSeconds: number

DateTime

beginningOfHour

Returns a new DateTime value that changes the Time value in the input to the beginning of the specified hour. The minutes and seconds in the input change to 00:00.

beginningOfHour(2021-03-15T18:23:20) = 2021-03-15T18:00:00

NA

dateTime: DateTime

DateTime

beginningOfDay

Returns a new DateTime value that changes the Time value in the input to the beginning of the specified day. The hours, minutes, and seconds in the input change to 00:00:00.

beginningOfDay(2021-03-15T18:23:20) = 2021-03-15T00:00:00

NA

dateTime: DateTime

DateTime

beginningOfWeek

Returns a new Date value that changes the Day value from the input to the beginning of the first day of the specified week. The function treats Sunday as the first day of the week.

beginningOfWeek(2021-03-15) = 2021-03-14

beginningOfWeek(today()) = 2021-03-14

NA

date: Date

Date

beginningOfWeek

Returns a new DateTime value that changes the Day and Time values from the input to the beginning of the first day of the specified week. The function treats Sunday as the first day of the week.

beginningOfWeek(2021-03-15T18:23:20) = 2021-03-14T00:00:00

beginningOfWeek(now()) = 2021-03-14T00:00:00

NA

dateTime: DateTime

DateTime

beginningOfMonth

Returns a new Date value that changes the Day value from the input to the first day of the specified month.

beginningOfMonth(2021-11-15) = 2021-11-01

beginningOfMonth(today()) = 2021-03-01

NA

date: Date

Date

beginningOfMonth

Returns a new DateTime value that changes the Day value from the input to the first day of the specified month. The day and time in the input changes to 01T00:00:00.

beginningOfMonth(2021-03-15T18:23:20) = 2021-03-01T00:00:00

beginningOfMonth(now()) = 2021-03-01T00:00:00

NA

dateTime: DateTime

DateTime

beginningOfYear

Returns a new Date value that changes the Month and Day values from the input to the first day of the specified year.

beginningOfYear(2021-11-15) = 2021-01-01

beginningOfYear(today()) = 2021-01-01

NA

date: Date

Date

beginningOfYear

Returns a new DateTime value that changes the Month and Day values from the input to the first day of the specified year. It also sets the Time value to 00:00:00. The month, day, and time in the input changes to 01-01T00:00:00.

beginningOfYear(2021-03-15T18:23:20) = 2021-01-01T00:00:00

beginningOfYear(now()) = 2021-01-01T00:00:00

NA

dateTime: DateTime

DateTime

daysBetween

Returns the number of days between two dates. If the to Date value is earlier than the from Date value, the function returns a negative number equal to the number of days between the two dates.

daysBetween(2020-03-15, 2021-03-15) = 365

NA

from: Date

to: Date

Number

daysBetween

Returns the number of days between two DateTime values. If the to DateTime value is earlier than the from DateTime value, the function returns a negative number equal to the number of days between the two DateTime values.

daysBetween(2020-03-15T18:23:20, 2021-03-15T02:23:20) = 365

NA

from: DateTime

to: DateTime

Number

month

Returns the numerical value of the month in the Date input.

month(2021-03-15) = 3

NA

date: Date

Number

month

Returns the numerical value of the month in the DateTime input.

month(2021-03-15T18:23:20) = 3

NA

dateTime: DateTime

Number

year

Returns the numerical value of the year in the Date input.

year(2021-03-15) = 2021

NA

date: Date

Number

year

Returns the numerical value of the year in the DateTime input.

year(2021-03-15T18:23:20) = 2021

NA

dateTime: DateTime

Number

fromDateToString

Transforms a date input value into a string value. Accepts a format and locale. The format parameter represents the required format of the output string. The default format is uuuu-MM-dd and the default locale is en-US; however, these defaults can be modified.

fromDateToString(2021-03-15, uuuu-dd-MM, en-US) = 2021-15-03

fromDateToString(2021-03-15, uuuu/MM/dd, en-US) = 2021/03/15

fromDateToString(2021-03-15, eeee, dd MMMM, ES) = lunes, 15 marzo

Format: The ISO-8601 formatting to use on the Date. It represents the desired format of the output string. For example, this parameter accepts character patterns based on the Java 8 java.time.format. The default format is uuuu-MM-dd.

Locale: Optional ISO 3166 country code to use, such as en-US, AR, or ES. When you pass a translatable format, such as eeee and MMMM, a locale (such as ES) transforms the corresponding numeric values to a localized string.

date: Date

format: String

locale: String

String

fromDateTimeToString

Transforms a dateTime input value into a string value. Accepts a format and locale. The format parameter represents the desired format of the output string. The default format is uuuu-MM-dd’T’HH:mm:ss’Z and the default locale is en-US; however, these defaults can be modified.

fromDateTimeToString(2021-03-15T23:57:59Z, uuuu-MM-dd’T’HH:mm:ss’Z, en-US) = 2021-03-15T23:57:59Z

fromDateTimeToString(2021-03-15T23:57:59Z, MMMM dd, ES) = marzo 15

Format: The ISO-8601 formatting to use on the DateTime. It represents the desired format of the output string. For example, this parameter accepts character patterns based on the Java 8 java.time.format. The default format is uuuu-MM-dd’T’HH:mm:ss’Z.

Locale: Optional ISO 3166 country code to use, such as en-US, AR, or ES. When you pass a translatable format, such as eeee and MMMM, a locale (such as ES) transforms the corresponding numeric values to a localized string.

dateTime: DateTime

format: String

locale: String

String

fromDateTimeToNumber

Transforms a dateTime input value into a number value. The number is in milliseconds or seconds, depending on the selected unit. The default unit is seconds.

fromDateTimeToNumber(2015-10-01T23:57:59Z, seconds) = 1443743879

fromDateTimeToNumber(2015-10-01T23:57:59Z, milliseconds) = 1443743879000

Unit: The unit of time to use for the conversion: "milliseconds" or "seconds". The default unit is "seconds."

dateTime: DateTime

unit: String

Number

fromDateToDateTime

Transforms a date input value into a dateTime. It does so by adding a time. The default time is T00:00:00Z. All manual entries will be interpreted in UTC.

fromDateToDateTime(2021-03-15, T00:00:00Z) = 2021-03-15T00:00:00Z

fromDateToDateTime(2021-03-15, T23:57:59Z) = 2021-03-15T23:57:59Z

NA

date: Date

time: String

DateTime

Data Types

The value that a Composer field can accept for a value is a data type. In Composer, the following data types are available:

Data Type Definition

Array

Provides a collection of a fixed number of components of the same data type.

Boolean

Evaluates to true or false.

Date

Stores a year, month, and day as yyyy-MM-dd.

DateTime

Stores a date and time within a time zone relative to Greenwich Mean Time (GMT). A time zone must include either the symbol + in the time value or the symbol - in the date value. For example, 12:30 p.m. on June 1, 2019, in the Macau time zone is represented as 2019-06-01T12:30:00+08:00.

List

Returns a list of objects, for example, the output of the Get Records action.

Number

Stores either a floating-point number in the range of 1.40129846432481707e-45 to 3.40282346638528860e+38 or an integer.

Object

Refers to a composite data type that can contain other data types as properties (boolean, date, number, and so on).

String

Stores text, numbers that are not number data types, or a combination of both, for example, 94u0sfjlk*(f!`lkkjd, 18005555555, or Fred.

Supported Keyboard Shortcuts

The Custom Expression Editor enables you to use keyboard shortcuts for mathematical operators. When inserting mathematical operators, press one of Control + Shift + <+, (, ), or *>. For example, to enter a operator, press Control + Shift +.

For / and -, the Shift key is not required. For example, to insert a /, you can press Control + /.

Access the Custom Expression Editor

To access the Custom Expression Editor:

  1. From the Composer Flows tab, open a flow.

  2. Click Edit.

  3. In an action field, in a value in the query builder, or in the value of an If/Else Block control, select Custom Expression fx from the drop-down menu.
    The Custom Expression Editor appears.

Add a Custom Expression to an Action

When adding a custom expression, place the cursor over elements in the Custom Expression Editor window to trigger context popovers containing helpful suggestions and in-app support.

To add a custom expression to an action:

  1. In the Custom Expression Editor left pane, click one of the following tabs:

    1. Function, to view or search for a function

    2. Data, to view or search for a field or data pill

    3. Operator, to view or search for an operator

  2. Select the available functions, fields, data pills, or operators for your custom expression from the left pane.
    Your selections appear in the <Field Name> box in the right pane. The syntax of your custom expression is validated automatically.

  3. If you want to reuse the expression in the <Field Name> box in another field, copy it.

  4. After the custom expression is created and validated, click Apply.

  5. Click Save.
    The custom expression is added to the field.

Edit a Custom Expression

To edit an existing custom expression in an action:

  1. From the Composer Flows tab, open a flow.

  2. Click Edit

  3. In an action field containing your custom expression, click the pencil icon.
    The Custom Expression Editor appears.

  4. In the <Field Name> box in the right pane of the Custom Expression Editor, either select and delete the existing custom expression or place your cursor where you want to add items from the left pane.

  5. In the left pane, select from the available functions, fields, data pills, or operators.
    Your selections appear in the <Field Name> box in the right pane. The syntax of your edited custom expression is validated automatically.

  6. After your custom expression is edited and validated, click Apply.

  7. Click Save.
    Your custom expression is edited.

Delete a Custom Expression

To delete an existing custom expression in an action:

  1. From the Composer Flows tab, open a flow.

  2. Click Edit

  3. In an action field containing a custom expression, click the X icon.
    The custom expression is deleted from the field.

  4. If your implementation requires this field to contain a value, either add a new custom expression or select a value from the drop-down menu.

  5. On the Flow Details page, click Save.
    The custom expression is deleted. If your environment requires a value in the custom expression field, your addition or selection is saved.

Was this article helpful?

💙 Thanks for your feedback!

Edit on GitHub
Submit your feedback!
Share your thoughts to help us build the best documentation experience for you!
Take our latest survey!