Expression language
Choices and records
Reference for the Choice Functions category (First Non-Empty, Is One Of, Is Between, Switch) and for option labels, record links and the organization URL.
This page covers two groups of functions that help you choose between values and talk about records:
- The Choice Functions category picks a value from several candidates: the first one that is filled in, the one that matches a case, or whether a value is in a list or a range.
- Option Label, Record Link and Organization URL (listed under Text Functions) turn choice values and records into text that people can read and click, for emails, notifications and descriptions.
Choice Functions
Section titled “Choice Functions”First Non-Empty
Section titled “First Non-Empty”Coalesce(value1, value2, …)Returns the first value that is not empty. Use it for fallbacks.
| Parameter | Type | Required | Description |
|---|---|---|---|
| Values (the first non-empty one is used) | Any, all the same type | Yes, at least two | The candidates, in order of preference. |
- Empty text
""counts as empty. - Later values are only calculated when the earlier ones are empty.
- If every value is empty, the result is empty. Test it with Null if needed.
Examples
Coalesce(mobilephone, telephone1, Account.telephone1)gives the best number to call a contact on.Coalesce(Opportunity.ownerid, Account.ownerid)assigns a task to the opportunity owner, or to the account owner when there is none.
Is One Of
Section titled “Is One Of”value in (candidate1, candidate2, …)Returns Yes when a value equals any of the candidates. It is a shorter way to write several Is Equal To checks joined by Or.
| Parameter | Type | Required | Description |
|---|---|---|---|
| Value | Any | Yes | The value to check. |
| Equals one of | Same type as the value | Yes, at least one | The candidates. |
- Uses the Is Equal To rules: text is case-sensitive, and lookups match when they point to the same row.
- Checking stops at the first match.
Examples
customertypecode in (Competitor, Partner)excludes competitors and partners from a promotion.address1_country in ("Jordan", "UAE", "KSA")assigns accounts to the Middle East sales team.
Is Between
Section titled “Is Between”IsBetween(value, from, to)Returns Yes when a number or date is within a range.
| Parameter | Type | Required | Description |
|---|---|---|---|
| Value | Number or Date and Time | Yes | The value to check. |
| From | Same type as the value | Yes | The lower end. |
| To | Same type as the value | Yes | The upper end. |
- Both ends are included:
IsBetween(5, 1, 5)is Yes. - An empty number counts as 0.
Examples
IsBetween(revenue, 1000000, 5000000)puts an account in the mid-market segment.IsBetween(estimatedclosedate, Start Of Month(Now), Add Days(Add Months(Start Of Month(Now), 1), -1))finds opportunities closing this month.
Switch
Section titled “Switch”Switch(value; when1 => then1; when2 => then2; else otherwise)Compares a value with a list of cases and returns the result of the first case that matches. Easier to read than nested If Condition functions.
| Parameter | Type | Required | Description |
|---|---|---|---|
| Value | Any | Yes | The value to compare. |
| Cases | Pairs of When and Then | Yes | When is a value to compare with; Then is the result if it matches. |
| Otherwise | Same type as the Then results | Yes | The result when no case matches. |
- Cases are checked in order, using the Is Equal To rules. The first match wins.
- Only the matching result is calculated.
- All Then results and Otherwise must have the same type.
- An empty number result becomes
0.
Example: Switch(prioritycode; High => 4; Normal => 24; else 72) gives the SLA response time in hours for a case.
Choice labels and record links
Section titled “Choice labels and record links”Option Label
Section titled “Option Label”OptionLabel(value, language)Returns the display label of a choice, a multi-select choice or a Yes/No value.
| Parameter | Type | Required | Description |
|---|---|---|---|
| Option set value | Choice, multi-select Choice or Yes/No | Yes | The value whose label you want. |
| Language code (optional, e.g. 1033 or 1025) | Number | No | The language of the label, such as 1033 for English or 1025 for Arabic. When empty, the current user’s language is used. |
- For a multi-select choice, the result is a List of Text with one label per selected option, in order. Combine it with Join to get one text.
- For a Yes/No column, the result is the column’s own Yes or No label.
- When a translation is missing, the English label is used, then any available label, and finally the option’s number.
- An empty value gives empty text.
Examples
Concatenate("Priority: ", OptionLabel(prioritycode))gives “Priority: High” for a notification.OptionLabel(statuscode, 1025)gives the Arabic status label for an SMS to an Arabic-speaking customer.Join(OptionLabel(new_interests), ", ")gives “Golf, Sailing”.
Record Link
Section titled “Record Link”RecordUrl(record, appId)Returns a web link that opens a record’s form in the browser.
| Parameter | Type | Required | Description |
|---|---|---|---|
| Record or lookup | Lookup, Row, User, Team or Owner | Yes | The record to link to. |
| App id (optional) | Text or Unique Identifier | No | The ID of a model-driven app, to open the record inside that app. An ID that is not a valid GUID is ignored. |
- Returns empty text when there is no record, or the record has not been saved yet.
Example: Format("Please review case {0}: {1}", title, RecordUrl(incidentid)) builds the body of an approval email with a link straight to the case.
Organization URL
Section titled “Organization URL”OrganizationUrl()Returns the web address of your organization, without a trailing slash, for example https://contoso.crm4.dynamics.com. It has no parameters.
On Dynamics 365 CE on-premises it returns the organization’s web address as configured on the server. With the usual path-based addresses this includes the organization name, for example https://crm.contoso.local/Contoso; check the value once in your environment.
Example: Concatenate("Sent from ", OrganizationUrl()) at the end of a notification tells recipients which environment it came from, for example a test or a production environment.
Lookups to more than one table
Section titled “Lookups to more than one table”Regarding
Section titled “Regarding”Some lookups can point to rows of several tables: a task’s Regarding, a case’s Customer (account or contact), or an Owner (user or team). When a slot expects such a lookup, the picker offers a Regarding card. Pick the table first, then the value for that table, for example a row read earlier in the flow or a lookup from the current record.
Example: to create a follow-up task about a case, set the task’s Regarding with the Regarding card: choose the Case table, then pick the case the flow is working on.