Contact Free trial Login

orElse

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

Name Description

previous

Previous try result

orElse

The next option to try if the previous fails

Example

This example waits shows how to chain different try

Source

%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

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

We use cookies to make interactions with our websites and services easy and meaningful, to better understand how they are used and to tailor advertising. You can read more and make your cookie choices here. By continuing to use this site you are giving us your consent to do this.