---
schema_version: "1"
id: 04c4d3806d6a3bde1eea0e3d71878b91af66b549996ccf327d6f4f9d8b7623cf
title: orElse
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/dataweave/2.3/dw-runtime-functions-orelse.md
canonical_url: https://docs.mulesoft.com/dataweave/2.3/dw-runtime-functions-orelse
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 50546c8a3ad6ea0435563ccd4292ca3f67d479509c3f325b06feacc1fd9f13ed
description: MuleSoft Documentation Site
release: "2.3"
latest: false
---
---
product: DataWeave
version: 2.3
---

# orElse

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

## orElse(TryResult<T>, () -> R): T | R

Returns the result of the `orElse` if the `previous` try result failed if not returns the result of
the `previous`

_Introduced in DataWeave 2.2.0. Supported by Mule 4.2 and later._

### Parameters

<table><colgroup><col> <col></colgroup><thead><tr><th>Name</th><th>Description</th></tr></thead><tbody><tr><td><p><code>previous</code></p></td><td><p>Previous try result</p></td></tr><tr><td><p><code>orElse</code></p></td><td><p>The next option to try if the previous fails</p></td></tr></tbody></table>

### Example

This example demonstrates how to specify the next expression to evaluate after a call to `try`
fails.

#### Source

```DataWeave
%dw 2.0
import * from dw::Runtime
var user = {}
var otherUser = {name: "DW"}
output application/json
---
{
    a: try(() -> user.name!) orElse "No User Name",
    b: try(() -> otherUser.name) orElse "No User Name"
}
```

#### Output

```JSON
{
  "a": "No User Name",
  "b": "DW"
}
```
