nerdexam
MuleSoft

MCD-LEVEL-1 · Question #102

A Utlility.dwl is located in a Mule project at src/main/resources/modules. The Utility.dwl file defines a function named encryptString that encrypts a String What is the correct DataWeave to call…

The correct answer is B. 1. %dw 2.0 2. output application/json 3. import modules::Utility 4. --- 5. encryptString( "John Smith" ). Correct answer is output application/json import modules::Utility Utility::encryptString( "John Smith" ) DataWeave 2.0 functions are packaged in modules. Before you begin, note that DataWeave 2.0 is for Mule 4 apps. For Mule 3 apps, refer to DataWeave Operators in the Mule 3.9…

Transforming Data with DataWeave

Question

A Utlility.dwl is located in a Mule project at src/main/resources/modules. The Utility.dwl file defines a function named encryptString that encrypts a String What is the correct DataWeave to call the encryptString function in a Transform Message component? A. 1. %dw 2.0 2. output application/json 3. import modules::Utility 4. --- 5. Utility::encryptString( "John Smith" ) B. 1. %dw 2.0 2. output application/json 3. import modules::Utility 4. --- 5. encryptString( "John Smith" ) C. 1. %dw 2.0 2. output application/json 3. import modules.Utility 4. --- 5. encryptString( "John Smith" ) D. 1. %dw 2.0 2. output application/json 3. import modules.Utility 4. ---

Options

  • A
    1. %dw 2.0
    2. output application/json
    3. import modules::Utility

    4. Utility::encryptString( "John Smith" )
  • B
    1. %dw 2.0
    2. output application/json
    3. import modules::Utility

    4. encryptString( "John Smith" )
  • C
    1. %dw 2.0
    2. output application/json
    3. import modules.Utility

    4. encryptString( "John Smith" )
  • D
    1. %dw 2.0
    2. output application/json
    3. import modules.Utility

    4. Utility.encryptString( "John Smith" )

How the community answered

(35 responses)
  • A
    3% (1)
  • B
    71% (25)
  • C
    9% (3)
  • D
    17% (6)

Explanation

Correct answer is output application/json import modules::Utility Utility::encryptString( "John Smith" ) DataWeave 2.0 functions are packaged in modules. Before you begin, note that DataWeave 2.0 is for Mule 4 apps. For Mule 3 apps, refer to DataWeave Operators in the Mule 3.9 documentation. For other Mule versions, you can use the version selector for the Mule Runtime table of contents. Functions in the Core (dw::Core) module are imported automatically into your DataWeave scripts. To use other modules, you need to import the module or functions you want to use by adding the import directive to the head of your DataWeave script, for example: import dw::core::Strings import camelize, capitalize from dw::core::Strings import * from dw::core::Strings The way you import a module impacts the way you need to call its functions from a DataWeave script. If the directive does not list specific functions to import or use * from to import all functions from a function module, you need to specify the module when you call the function from your script. For example, this import directive does not identify any functions to import from the String module, so it calls the pluralize function like this: Strings::pluralize("box"). import dw::core::Strings output application/json { 'plural': Strings::pluralize("box") }

Topics

#DataWeave#custom modules#import syntax#function invocation

Community Discussion

No community discussion yet for this question.

Full MCD-LEVEL-1 Practice