Script Class

Contains the createScript() method to load DataWeave scripts and the execute() method to obtain script output in a DataWeave.Result object.

DataWeave

This example runs a DataWeave script from Apex and retrieves the resulting script output. First deploy the script to the org as ContactsToJson.dwl.

Then, execute the script from Apex.

The following are methods for Script.

  • createScript(scriptName)

    Loads a DataWeave 2.0 script from the .dwl metadata file that is deployed in an org. The script can then be run using the Script.execute method.

  • createScript(namespace, scriptName)

    Loads a DataWeave 2.0 script from a specified namespace. The script can then be run using the Script.execute method.

  • execute(parameters)

    Executes the DataWeave script that is loaded using the createScript() method and returns the script output.

  • toString()

    Returns the name of the script.

Loads a DataWeave 2.0 script from the .dwl metadata file that is deployed in an org. The script can then be run using the Script.execute method.

public static createScript(String scriptName)

  • scriptName:

    Type: String

    The name of the deployed metadata .dwl script (not including the file extension).

Type: DataWeave.Script

DataWeave script that is used as a parameter in the Script.execute() method.

Loads a DataWeave 2.0 script from a specified namespace. The script can then be run using the Script.execute method.

public static dataweave.Script createScript(String namespace, String scriptName)

  • namespace:

    Type: String

    The namespace name for the deployed script. If the namespace name is null, the caller namespace is used. If the namespace name is empty, the org namespace is used.

  • scriptName:

    Type: String

    The name of the deployed metadata .dwl script (not including the file extension).

Type: DataWeave.Script

DataWeave script that is used as a parameter in the Script.execute() method.

Executes the DataWeave script that is loaded using the createScript() method and returns the script output.

public execute(Map<String,Object> parameters)

  • parameters:

    Type: Map<String,Object> Input to the DataWeave script. The keys correspond to the input directive names defined in the DataWeave header. See Input Directive and DataWeave Header.

Type: DataWeave.Result

The DataWeave.Result object contains the script output.

Returns the name of the script.

public String toString()

Type: String