Contact Us 1-800-596-4880

lookup

lookup(flowName: String, payload: Any, timeoutMillis: Number = 2000)

This function enables you to execute a flow within a Mule app and retrieve the resulting payload.

It works in Mule apps that are running on Mule Runtime version 4.1.4 and later.

Similar to the Flow Reference component (recommended), the lookup function enables you to execute another flow within your app and to retrieve the resulting payload. It takes the flow’s name and an input payload as parameters. For example, lookup("anotherFlow", payload) executes a flow named anotherFlow.

The function executes the specified flow using the current attributes, variables, and any error, but it only passes in the payload without any attributes or variables. Similarly, the called flow will only return its payload.

The lookup function does not support calling subflows.

Always keep in mind that a functional language like DataWeave expects the invocation of the lookup function to not have side effects. So, the internal workings of the DataWeave engine might cause a lookup function to be invoked in parallel with other lookup functions, or not to be invoked at all.

MuleSoft recommends that you invoke flows with the Flow Ref (flow-ref) component, using the target attribute to put the result of the flow in a var and then referencing that var from within the DataWeave script.

Parameters

Name Description

flowName

A string that identifies the target flow.

payload

The payload to send to the target flow, which can be any (Any) type.

timeoutMillis

Optional. Timeout (in milliseconds) for the execution of the target flow. Defaults to 2000 milliseconds (2 seconds) if the thread that is executing is CPU_LIGHT or CPU_INTENSIVE, or 1 minute when executing from other threads. If the lookup takes more time than the specified timeoutMillis value, an error is raised.

Example

This example shows XML for two flows. The lookup function in flow1 executes flow2 and passes the object {test:'hello '} as its payload to flow2. The Set Payload component (<set-payload/>) in flow2 then concatenates the value of {test:'hello '} with the string world to output and log hello world.

Source

<flow name="flow1">
  <http:listener doc:name="Listener" config-ref="HTTP_Listener_config"
    path="/source"/>
  <ee:transform doc:name="Transform Message" >
    <ee:message >
      <ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
Mule::lookup('flow2', {test:'hello '})]]></ee:set-payload>
    </ee:message>
  </ee:transform>
</flow>
<flow name="flow2" >
  <set-payload value='#[payload.test ++ "world"]' doc:name="Set Payload" />
  <logger level="INFO" doc:name="Logger" message='#[payload]'/>
</flow>