---
schema_version: "1"
id: ee5ecd29299ec9f1aa439035fa56150cce92e5f095fb4594cd45fd5517c86773
title: Change the Value of a Field
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/dataweave/2.11/dataweave-cookbook-change-value-of-a-field.md
canonical_url: https://docs.mulesoft.com/dataweave/2.11/dataweave-cookbook-change-value-of-a-field
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 848f47e7f4ce5f34cdf349fc21f7e2c1bc60bbd32d2ed15eabf9fe549d50c65d
description: MuleSoft Documentation Site
release: "2.11"
latest: false
---
---
product: DataWeave
version: 2.11
keywords: studio, anypoint, transform, transformer, format, rename, xml, json, metadata, dataweave, data weave, datamapper, dwl, dfl, dw, output structure, input structure, map, mapping, update
---

# Change the Value of a Field

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

The following DataWeave examples show how to use `update` and `mask` to change the values of some
XML elements.

## Example: Using Update to Change Values

This example uses:

- `update` to update specified fields of the payload with new values

- single-value (`.`) and multi-value (`.*`) selectors to navigate the payload and select the fields
  to update

The following script shows how the `update` operator works. The example creates a new `users` list
by updating each `user` in the payload with a new `user`. The transformation converts `first_name`,
`middle_name` and `last_name` to uppercase values:

DataWeave Script:

```dataweave
%dw 2.0
output application/xml
---
payload update {
  case user at .users.*user -> user update {
    case .personal_information.first_name -> upper(user.personal_information.first_name)
    case .personal_information.middle_name -> upper(user.personal_information.middle_name)
    case .personal_information.last_name -> upper(user.personal_information.last_name)
  }
}
```

Input XML Payload:

```xml
<users>
    <user>
        <personal_information>
            <first_name>Emiliano</first_name>
            <middle_name>Romoaldo</middle_name>
            <last_name>Lesende</last_name>
            <ssn>001-08-84382</ssn>
        </personal_information>
        <login_information>
            <username>3miliano</username>
            <password>mypassword1234</password>
        </login_information>
    </user>
    <user>
        <personal_information>
            <first_name>Mariano</first_name>
            <middle_name>Toribio</middle_name>
            <last_name>de Achaval</last_name>
            <ssn>002-05-34738</ssn>
        </personal_information>
        <login_information>
            <username>machaval</username>
            <password>mypassword4321</password>
        </login_information>
    </user>
</users>
```

Output XML:

```xml
<?xml version="1.0" encoding="UTF-8"?>
<users>
  <user>
    <personal_information>
      <first_name>EMILIANO</first_name>
      <middle_name>ROMOALDO</middle_name>
      <last_name>LESENDE</last_name>
      <ssn>001-08-84382</ssn>
    </personal_information>
    <login_information>
      <username>3miliano</username>
      <password>mypassword1234</password>
    </login_information>
  </user>
  <user>
    <personal_information>
      <first_name>MARIANO</first_name>
      <middle_name>TORIBIO</middle_name>
      <last_name>DE ACHAVAL</last_name>
      <ssn>002-05-34738</ssn>
    </personal_information>
    <login_information>
      <username>machaval</username>
      <password>mypassword4321</password>
    </login_information>
  </user>
</users>
```

## Example: Using Mask to Change Values

DataWeave provides a simple way to mask values, without specifying the path to each field:

- `mask` updates all simple elements that match the selected name throughout the input with the
  specified mask.

The following example masks the `ssn` and `password` values with a set of asterisks (`****`):

DataWeave Script:

```dataweave
%dw 2.0
import * from dw::util::Values
output application/xml
---
(payload mask "ssn" with "****") mask "password" with "****"
```

Input XML Payload:

```xml
<?xml version="1.0" encoding="UTF-8"?>
<users>
  <user>
    <personal_information>
      <first_name>EMILIANO</first_name>
      <middle_name>ROMOALDO</middle_name>
      <last_name>LESENDE</last_name>
      <ssn>001-08-84382</ssn>
    </personal_information>
    <login_information>
      <username>3miliano</username>
      <password>mypassword1234</password>
    </login_information>
  </user>
  <user>
    <personal_information>
      <first_name>MARIANO</first_name>
      <middle_name>TORIBIO</middle_name>
      <last_name>DE ACHAVAL</last_name>
      <ssn>002-05-34738</ssn>
    </personal_information>
    <login_information>
      <username>machaval</username>
      <password>mypassword4321</password>
    </login_information>
  </user>
</users>
```

Output XML:

```xml
<?xml version="1.0" encoding="UTF-8"?>
<users>
  <user>
    <personal_information>
      <first_name>EMILIANO</first_name>
      <middle_name>ROMOALDO</middle_name>
      <last_name>LESENDE</last_name>
      <ssn>****</ssn>
    </personal_information>
    <login_information>
      <username>3miliano</username>
      <password>****</password>
    </login_information>
  </user>
  <user>
    <personal_information>
      <first_name>MARIANO</first_name>
      <middle_name>TORIBIO</middle_name>
      <last_name>DE ACHAVAL</last_name>
      <ssn>****</ssn>
    </personal_information>
    <login_information>
      <username>machaval</username>
      <password>****</password>
    </login_information>
  </user>
</users>
```

## Related Examples

- [Transform XML to JSON](https://docs.mulesoft.com/dataweave/2.11/dataweave-cookbook-perform-basic-transformation)

- [Output a Field When Present](https://docs.mulesoft.com/dataweave/2.11/dataweave-cookbook-output-a-field-when-present)

- [Insert an Attribute into an XML Tag](https://docs.mulesoft.com/dataweave/2.11/dataweave-cookbook-insert-attribute)

## See Also

- [DataWeave Types](https://docs.mulesoft.com/dataweave/2.11/dataweave-types)

- [DataWeave Selectors](https://docs.mulesoft.com/dataweave/2.11/dataweave-selectors)

- [DataWeave Cookbook](https://docs.mulesoft.com/dataweave/2.11/dataweave-cookbook)
