Formatting strings in rules

From Resco's Wiki
Jump to navigation Jump to search

One of the available operations in Rules editor when building a function step is Format. The purpose of this operation is to convert a string or a series of strings to a custom format.

This operation functions similarly to the .NET composite formatting feature:

The (...) feature takes a list of objects and a composite format string as input. A composite format string consists of fixed text intermixed with indexed placeholders, called format items, that correspond to the objects in the list. The formatting operation yields a result string that consists of the original fixed text intermixed with the string representation of the objects in the list. (Microsoft documentation)

Additional related operations include:

  • Format Text - Returns a formatted string that can contain references to entity fields using the dot notation - {entity.field:format} (Example)
  • Format Single - Returns a formatted string with lookup target information. This operation uses two arguments. The first is a text with placeholders: {1} for entity ID, {2} for entity name. The second argument is a lookup field. More info Webinar


The Format operation in Rules editor has two arguments (parameters). The first argument describes how the second argument should be formatted.

  • Arg1: Text = composite format string
  • Arg2: StringList = format items

The first argument is composite format string (Microsoft documentation). Essentially, it says how the result should look, with placeholders for strings from the second argument.

  • The placeholders are numbers in curly brackets that correspond to the index of a format item in argument 2.
  • The first format item has the index {0}.
  • The same format item can be used multiple times in a single composite format string.
  • Each format item can be further customized. For example, you can return only a date portion of a datetime variable {0:d}, you can apply currency formatting to a number {0:C2}, and much more.

The second argument is a StringList type of variable, a series or array of strings (or format items).

Format examples

Form button that fills an email address

Add a button to your form. Add a Button Click rule that builds your email address from first name, last name, and a static suffix.

Formatting strings in rules: Format string list example

This is how it looks in the app:

Formatting strings in rules: Set email example

More composite format string examples

Argument 1 Argument 2 Result
Let's meet on {0:d} at {0:t}. DateTime field Let's meet on 4/10/2015 at 9:00 AM.
The price of {0} is {1:C2}. product name, price The price of Car Door Hanging Plate is $89.

Format Text example

In this example, add a button that concatenates multiple entity fields (with formatting) into a single sentence.

Formatting strings in rules: Format text example
Here's the important part: "Format Text" in action.
The property {}, first offered in {Entity.createdon:MMMM yyyy}, located in {Entity.address_city} ({Entity.address_country}) is available from {Entity.seller} for {Entity.price:C}.
Result in the app
Formatting strings in rules: Real estate details in a sentence

See also