---
schema_version: "1"
id: 993c2310eea301f8c410b53fd35c5752e924a0ec7da6ad9497026b75b3d1d62f
title: orElse
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/dataweave/latest/dw-runtime-functions-orelse.md
canonical_url: https://docs.mulesoft.com/dataweave/latest/dw-runtime-functions-orelse
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 3f9359bb5d8006353c57d1f204acdd3f31fcf21389480eb32ef23b49f583f209
description: MuleSoft Documentation Site
release: "2.13"
latest: true
---
---
product: DataWeave
version: 2.13
is-latest-version: true
---

# orElse

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

## orElse<T, E, R>(previous: Result<T, E>, orElse: () -> R): T | R

Returns the result of the `orElse` argument if the `previous` argument to `try` fails. Otherwise,
the function returns the value of the `previous` argument.

_Introduced in DataWeave version 2.2.0._

### 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>Result from a previous call to <code>try</code>.</p></td></tr><tr><td><p><code>orElse</code></p></td><td><p>Argument to return if the <code>previous</code> argument fails.</p></td></tr></tbody></table>

### Example

This example waits shows how to chain different try

#### 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"
}
```
