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

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