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

# orElse

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

## orElse<T, R>(previous: TryResult<T>, 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"
}
```
