Formatting strings in rules: Difference between revisions
No edit summary |
Marek Rodak (talk | contribs) No edit summary |
||
| Line 28: | Line 28: | ||
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. | 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. | ||
[[File:Format string list example.png|600px]] | [[File:Format string list example.png|alt=Formatting strings in rules: Format string list example|600px]] | ||
This is how it looks in the app: | This is how it looks in the app: | ||
[[File:Set email example.png|300px]] | [[File:Set email example.png|alt=Formatting strings in rules: Set email example|300px]] | ||
=== More composite format string examples === | === More composite format string examples === | ||
| Line 51: | Line 51: | ||
;Rule | ;Rule | ||
:[[File:Format text example.png|600px]] | :[[File:Format text example.png|alt=Formatting strings in rules: Format text example|600px]] | ||
:Here's the important part: "Format Text" in action. | :Here's the important part: "Format Text" in action. | ||
:<code>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}.</code> | :<code>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}.</code> | ||
| Line 57: | Line 57: | ||
;Result in the app | ;Result in the app | ||
:[[File:Real estate details in a sentence.png]] | :[[File:Real estate details in a sentence.png|alt=Formatting strings in rules: Real estate details in a sentence]] | ||
== See also == | == See also == | ||
Latest revision as of 09:09, 16 November 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. 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
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
