---
schema_version: "1"
id: 8cab34368cfb400ccf0329600b75ef574670ef29382754291a423e1c1839310f
title: Dynamic Evaluate (<ee:dynamic-evaluate/>)
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/anypoint-code-builder/acb-component-dynamic-evaluate.md
canonical_url: https://docs.mulesoft.com/anypoint-code-builder/acb-component-dynamic-evaluate
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 66129fc5cfa50c9c46512dea4f5598dc9b46eeb36a3bf2a02f7970a1cc38e37a
description: MuleSoft Documentation Site
latest: true
---
---
product: Anypoint Code Builder
version: master
---

# Dynamic Evaluate (<ee:dynamic-evaluate/>)

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

Evaluates an expression to select a DataWeave script, and then executes the new script to generate a
result.

The script can use any of the usual
[predefined variables](https://docs.mulesoft.com/dataweave/2.4/dataweave-variables-context), such as `message`,
`payload`,`vars`, or `attributes`, but you can also add custom ones by providing a set of key-value
pairs.

## Component XML

This component supports the following XML structure:

```xml
<ee:dynamic-evaluate
  expression=""
  doc:name="Dynamic evaluate"
  doc:id="ojfqoz">
  <ee:parameters>#[]</ee:parameters>
</ee:dynamic-evaluate>
```

Dynamic Evaluate (`<ee:dynamic-evaluate/>`) attributes are configurable through the UI and XML.

<table><colgroup><col> <col> <col></colgroup><thead><tr><th>Attribute Name</th><th>Attribute XML</th><th>Description</th></tr></thead><tbody><tr><td><p><strong>Dynamic evaluate</strong> (default)</p></td><td><p><code>doc:name</code></p></td><td><div><div><p>Editable name for the component to display in the canvas.</p></div></div></td></tr><tr><td><p>N/A</p></td><td><p><code>doc:id</code></p></td><td><div><div><p>Automatically generated identifier for the component.</p></div></div></td></tr><tr><td><p><strong>Expression</strong></p></td><td><p><code>expression</code></p></td><td><div><div><p>Expression that selects a DataWeave script that Mule executes, for example, <code>expression="#[vars.generateOrderScript]"</code>.</p></div></div></td></tr><tr><td><p><strong>Additional Bindings</strong></p></td><td><p><code>parameters</code></p></td><td><div><div><p>N/A</p></div></div></td></tr><tr><td><p><strong>Target Variable</strong></p></td><td><p><code>target</code></p></td><td><div><div><p>Name of the variable in which you want to store message data. Names can only include numbers, characters, and underscores. For example, hyphens are not allowed in the name. See <a href="https://docs.mulesoft.com/mule-runtime/latest/target-variables">Enrich Data with Target Variables</a> in the Mule documentation.</p></div></div></td></tr><tr><td><p><strong>Target Value</strong></p></td><td><p><code>targetValue</code></p></td><td><div><div><p>Value of the data to store in the target variable. By default, the value is the message payload (payload). The field accepts any value that a variable accepts: any supported data type, DataWeave expressions, the keywords <code>payload</code>, <code>attributes</code>, and <code>message</code>, but not the keyword <code>vars</code>. See <a href="https://docs.mulesoft.com/mule-runtime/latest/target-variables">Enrich Data with Target Variables</a> in the Mule documentation.</p></div></div></td></tr></tbody></table>

`<ee:parameters/>` is a child element of Dynamic Evaluate.

<table><colgroup><col> <col></colgroup><thead><tr><th>Child Element</th><th>Description</th></tr></thead><tbody><tr><td><p><code>&lt;ee:parameters/&gt;</code></p></td><td><div><div><p>Key-value pairs that serve as parameters that the DataWeave script can evaluate, for example, <code>&lt;ee:parameters&gt;#[{name: attributes.queryParams.userName}]&lt;/ee:parameters&gt;</code>.</p></div></div></td></tr></tbody></table>

## Example

The following example selects a script from a database through a `userId` query parameter and stores
that script in a `userScript` variable. Dynamic Evaluate (`<ee:dynamic-evaluate/>`) accesses the
`userScript` variable to invoke the script by using the provided parameter `name`, which contains
the value of `attributes.queryParams.userName`.

```xml
<flow name="dynamic-evaluate-example-flow">
  <http:listener config-ref="HTTP_Listener_Configuration" path="/"/>
  <!-- This SQL query uses queryParams.userId to dynamically select a DataWeave script stored in a Database,
  and then assign this script to target variable userScript-->
  <db:select config-ref="dbConfig" target="userScript">
    <db:sql>#["SELECT script FROM SCRIPTS WHERE ID = $(attributes.queryParams.userId)"]</db:sql>
  </db:select>
  <!-- The dynamic evaluate component executes the script stored in vars.userScript-->
  <ee:dynamic-evaluate expression="#[vars.userScript]">
    <!-- This line sets a parameter called 'name', so the expression in the Dynamic Evaluate component can use it -->
    <ee:parameters>#[{name: attributes.queryParams.userName}]</ee:parameters>
  </ee:dynamic-evaluate>
</flow>
```

Assume that the scripts `lsalander` and\`mblomkvist\` are stored in this example’s database:

Example: lsalander script

output application/json
---

{ message: "Order " ++ attributes.queryParams.orderId ++ " has been received from " ++ name, items:
payload.items }

Example: mblomkvist script

output application/x-www-form-urlencoded
---

{ message: "Order " ++ attributes.queryParams.orderId ++ " has been received from " ++ name, items:
payload.items }

### Example Application Behavior

When Mule application [example](#example1) receives `lsalander` as the `queryParams.userId` in the
request, Mule executes the `lsalander` script, which results in a JSON response. If the application
receives `mblomkvist` as the `queryParams.userId` value, Mule executes a different script that
generates a `x-www-form-urlencoded` response.

The example demonstrates how the response type can be parameterized based on the user, but the
entire response can be parameterized to suit user needs.

## See Also

- [DataWeave Overview](https://docs.mulesoft.com/dataweave/2.4/)
