FoMS Experts

News / Exam Questions

QUESTION, ANSWER, EXPLANATION

Exam Question MS-21-019 for MuleSoft Certified Developer (MCD) - Level 1

Exam Question MS-21-019 for MuleSoft Certified Developer (MCD) - Level 1
Share
FacebookGoogle plusLinkedInStumbleuponTwitter
FoMS24.2.2021

This question has been asked by one of our members and a similar question could most likely be on the exam. All answers have been verified by MuleSoft certified FoMS experts.

Question

A Mule project contains a DataWeave module called MyModule.dwl that defines a function named formatString. The module is located in the project's src/main/resources/modules folder. What is the correct way in DataWeave code to import MyModule using a wildcard and then call the module's formatString function?

Answer

The correct answer to this question is C.

Explanation

According to the MuleSoft documentation, there are several ways to import a module or elements in it:

1) Import the module, for example: import modules::MyModule. In this case, you must include the name of the module when you call the element (here, a function) in it, for example: MyModule::myFunc.

2) Import all elements from the module, for example: import * from modules::MyModule. In this case, you do not need to include the name of the module when you call the element. For example: myFunc("dataweave") ++ "name" works.

3) Import specific elements from a module, for example: import myFunc from modules::MyModule. In this case, you do not need to include the name of the module when you call the element. For example: myFunc("dataweave") ++ "name" works. You can import multiple elements from the module like this, for example: import myFunc someOtherFunction from modules::MyModule (assuming both myFunc and someOtherFunction are defined in the module).

The question fits to the second case from this explanation, so the correct answer is C, because in the answer C the module is being imported by using "::" and the function is being called by its name only.

Register now