Formatting strings in rules: Difference between revisions
No edit summary |
|||
| Line 22: | Line 22: | ||
The second argument is a [[Rules_editor#StringList_type|StringList]] type of variable, a series or array of strings (or '''format items'''). | The second argument is a [[Rules_editor#StringList_type|StringList]] type of variable, a series or array of strings (or '''format items'''). | ||
== | == Format examples == | ||
=== Form button that fills an email address === | === Form button that fills an email address === | ||
| Line 45: | Line 45: | ||
|} | |} | ||
== Format Text example == | |||
In this example, add a button that concatenates multiple entity fields (with formatting) into a single sentence. | In this example, add a button that concatenates multiple entity fields (with formatting) into a single sentence. | ||
Revision as of 10:57, 30 May 2023
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. More info Webinar
Arguments
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.
This is how it looks in the app:
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.
- Rule

- Here's the important part: "Format Text" in action.
The property {Entity.name}, 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
See also
- Formatting strings in Report Designer
- https://docs.microsoft.com/en-us/dotnet/standard/base-types/composite-formatting
- https://docs.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings
- https://docs.microsoft.com/en-us/dotnet/standard/base-types/custom-numeric-format-strings
