A synchronous PreOperation plug-in on the Update message of the invoice table must calculate a total from the quantity and unitprice columns. When a user changes only quantity, the code throws a KeyNotFoundException reading unitprice from the Target entity. What is the correct explanation and fix?
Select an answer to reveal the explanation.
Short Explanation
Target on an Update is a change slip, not the whole file: it lists only what the caller sent. Since unitprice didn't change, it isn't on the slip, so you grab it from a pre-image. The trap is filtering attributes; they decide when the step fires, not what's inside Target.
Full Explanation
On the Update message, the Target entity in InputParameters contains only the columns included in the update request, plus the primary key. When a user changes quantity alone, unitprice is absent from Target, so reading it by key throws. Registering a pre-image that includes unitprice gives the plug-in the stored value, and the code should prefer the Target value when present and fall back to the image otherwise, so the calculation is correct whichever column changed. Target is not read-only in PreOperation; this is the stage where changes to Target are saved with the operation. A post-image is not available in PreOperation, because the post-operation state of the row does not exist yet; post-images apply to PostOperation steps. Filtering attributes control whether the step is triggered and do not add columns to Target, so listing unitprice would only make the step run when it changes. Target is populated in PreValidation, PreOperation and PostOperation; moving the step to PostOperation would not add unchanged columns and would also prevent setting the total in the same save without a second update. Exam caveat: a Retrieve call can also fetch the value, but an image avoids an extra request. Operational check: update only quantity and confirm the trace log shows unitprice read from the pre-image.