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

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