0057

Survive Quote-to-Order

event-subscriber
quote-to-order
sales
table-extension

Survive Quote-to-Order

Sales reps tag every quote with the marketing campaign that produced it, and when a deal is won the quote is turned into a sales order by the standard conversion routine, codeunit 86 "Sales-Quote to Order" — base code you cannot modify, and it deletes the quote when it is done. Marketing wants the campaign trail to survive: the created order must still carry the tag, and it must be permanently marked as having been won from a quote.

Requirements

  1. Create a table extension for the Sales Header table with a field named "Campaign Tag" of type Text[30] and a field named "Converted From Quote" of type Boolean.
  2. When a sales quote is converted to a sales order by codeunit 86 "Sales-Quote to Order" (the routine behind the Make Order action), the created order must carry the same "Campaign Tag" value the quote had at conversion time; a blank tag must stay blank.
  3. The created order's "Converted From Quote" must be true.
  4. A sales order created directly — not by converting a quote — must keep "Converted From Quote" as false.
  5. The standard conversion result must stay intact: every item line of the quote must arrive on the created order with its item and quantity unchanged, and no extra lines may appear.
  6. Put your logic in a new codeunit — its name is up to you (not graded). Do not try to change base objects; extend them from the outside.

Pick all object and field IDs in the 50100–50199 range, and reference other objects by name, never by ID. No page extensions are needed — grading reads and writes the fields in code. Captions are good practice but not graded.

What the tests check

The tests build real sales quotes with the standard libraries and convert them by running codeunit 86 "Sales-Quote to Order" directly. They convert a quote carrying a generated 30-character tag and assert the created order's "Campaign Tag" matches character for character, assert "Converted From Quote" is true on the created order and false on an order created directly, and convert a quote whose tag was never filled in to check the order's tag stays blank. They also convert a quote with two item lines carrying generated quantities and assert the order has exactly those two lines with matching items and quantities, and they verify "Campaign Tag" is declared as exactly Text[30] by checking its type and maximum length, and "Converted From Quote" as a Boolean.

Learn More

Hint 1
You cannot edit codeunit 86 "Sales-Quote to Order", but you don't need to: it publishes integration events at every step of the conversion, and a subscriber in your own codeunit runs as if it were part of the routine. In VS Code, Shift+Alt+E lists every event you can subscribe to.
Hint 2
The conversion starts by copying the whole quote record into the new order record, so your "Campaign Tag" actually travels on its own — what no base code will ever do is set "Converted From Quote". Look for the event raised right after the order header is inserted: it hands you the new order (by var, so your changes are what gets saved) together with the source quote.
Hint 3
The subscriber is [EventSubscriber(ObjectType::Codeunit, Codeunit::"Sales-Quote to Order", 'OnAfterInsertSalesOrderHeader', '', false, false)] on a procedure taking var SalesOrderHeader: Record "Sales Header" and SalesQuoteHeader: Record "Sales Header" — set the flag (and copy the tag) on SalesOrderHeader; no Modify needed, the conversion saves the order right after the event.
ALBusiness Central 28.5
Press Compile to check your code compiles — Submit runs the tests.
The code editor is desktop-only
Open this problem on a computer to write and run code. Reading the description, tests and discussion works fine here.