nerdexam
Microsoft

MB-500 · Question #267

A company uses Dynamics 365 Finance. You implement the Insert method for a table you create. The class must meet the following requirements: - If FieldA is equal to "Hello," then FieldB must save…

The correct answer is A. public void insert() { switch (this.FieldA) { case "Hello": this.FieldB = 10; break; case "World": this.FieldB = 20; break; default: this.FieldB = 0; break; } super(); } C. public void insert() { if (this.FieldA == "Hello") { this.FieldB = 10; } else if (this.FieldA == "World") { this.FieldB = 20; } else { this.FieldB = 0; } super(); }. Options A and C are correct because they both set the field values before calling super(), which is the critical requirement in X++ table methods - super() triggers the actual database insert, so all field assignments must occur first. Both a switch statement (A) and an if/else…

Develop business logic

Question

A company uses Dynamics 365 Finance. You implement the Insert method for a table you create. The class must meet the following requirements: - If FieldA is equal to "Hello," then FieldB must save the integer value 10. - If FieldA is equal to "World," then FieldB must save the integer value 20. - Otherwise FieldB must save the integer 0. You need to implement the code. Which two code segments can you use? Each correct answer presents a complete solution. NOTE: Each correct selection is worth one point. A. B. C. D.

Exhibits

MB-500 question #267 exhibit 1
MB-500 question #267 exhibit 2
MB-500 question #267 exhibit 3
MB-500 question #267 exhibit 4

Options

  • Apublic void insert() { switch (this.FieldA) { case "Hello": this.FieldB = 10; break; case "World": this.FieldB = 20; break; default: this.FieldB = 0; break; } super(); }
  • Bpublic void insert() { if (this.FieldA == "Hello") { this.FieldB = 10; } else if (this.FieldA == "World") { this.FieldB = 20; } else { this.FieldB = 0; } super(); }
  • Cpublic void insert() { if (this.FieldA == "Hello") { this.FieldB = 10; } else if (this.FieldA == "World") { this.FieldB = 20; } else { this.FieldB = 0; } super(); }
  • Dpublic void insert() { switch (this.FieldA) { case "Hello": this.FieldB = 10; break; case "World": this.FieldB = 20; break; default: this.FieldB = 0; break; } super(); }

How the community answered

(24 responses)
  • A
    75% (18)
  • B
    17% (4)
  • D
    8% (2)

Explanation

Options A and C are correct because they both set the field values before calling super(), which is the critical requirement in X++ table methods - super() triggers the actual database insert, so all field assignments must occur first. Both a switch statement (A) and an if/else if/else chain (C) are valid X++ constructs for this conditional logic, giving two equally correct solutions.

Options B and D are wrong because, in the actual exam images, they call super() before the conditional logic - meaning the record is written to the database before FieldB is assigned, so the 10/20/0 values are never persisted correctly.

Memory tip: Think of super() in an insert() override as the "commit" button - always set your values first, then commit. A helpful phrase: "Prepare, then persist" - field logic comes before super().

Topics

#X++ code#switch statement#if-else#table insert method

Community Discussion

No community discussion yet for this question.

Full MB-500 Practice