ExamGecko
Question list
Search
Search

List of questions

Search

Related questions











Question 215 - MCD - Level 1 discussion

Report
Export

Refer to the exhibits.

What payload and variable are logged at the end of the main flow?

A.
[[5, 10, 15, 20], 1]
Answers
A.
[[5, 10, 15, 20], 1]
B.
[[5, 10, 15, 20], 5]
Answers
B.
[[5, 10, 15, 20], 5]
C.
[[Req5, Req10, Req15, Req20], 5]
Answers
C.
[[Req5, Req10, Req15, Req20], 5]
D.
[Req5Req10,Req15Req20, 5]
Answers
D.
[Req5Req10,Req15Req20, 5]
Suggested answer: B

Explanation:

Correct answer is [[5, 10, 15, 20], 5]

Key thing to note here is that any changes made to payload in for each loop are not available outside for each scope where as variable value updated in for each loop is visible out side for each loop too.

In this example , sequence can be described as follows

1) Payload is set to the value [5, 10, 15, 20]

2) Variable is set to the value of 1

3) For each loop is executed four times and in each loop payload value is updated to append 'Req' and variable is count is increased by 1

4) Once control comes out of for each , payload changes made within for each are not visible. Hence payload at this point of time is equal to payload available before entering for each loop which was [5, 10, 15, 20]. Similarly variable value updated in for each loop is also available outside hence variable value is 5 as it was updated in loop.

5) Hence correct answer is [[5, 10, 15, 20], 5]

For Each Scope

The For Each scope splits a payload into elements and processes them one by one through the components that you place in the scope. It is similar to afor-each/forloop code block in most programming languages and can process any collection, including lists and arrays. The collection can be any supported content type, such asapplication/json,application/java, orapplication/xml.

General considerations about the For Each scope:

By default, For Each tries to split the payload. If the payload is a simple Java collection, the For Each scope can split it without any configuration. The payload inside the For Each scope is each of the split elements. Attributes within the original message are ignored because they are related to the entire message.

For Each does not modify the current payload. The output payload is the same as the input.

For non-Java collections, such as XML or JSON, use a DataWeave expression to split data. Use theCollectionfield for this purpose.

asked 18/09/2024
Marco Morsiani
45 questions
User
Your answer:
0 comments
Sorted by

Leave a comment first