When Are Custom Integration…
If your shop sells by the carton and your warehouse…
The Client API reference Dynamics 365 developers need for form scripts is on Microsoft Learn under Client API reference for model-driven apps. To show a warning on a Dynamics 365 Sales quote, start with the form event that should trigger it. Get the current form from that event, read the seller’s entries and use formContext.ui.setFormNotification() to display the message.
Consider a seller who opens a draft quote with a discount already above the review threshold. A warning that appears only when the seller edits the discount comes too late. The script needs to check the quote when it opens as well as when a value changes.
Microsoft organises the reference by object. An attribute gives you the value of a column on the form. A control displays the value and may let someone edit it. To read a discount, get its attribute and call getValue(). To hide the box where the seller enters it, find the control and call setVisible(false).
Some tasks sit outside the current form. Use Xrm.Navigation to open another form or display a dialogue. Use Xrm.WebApi to read or update a Dataverse record, such as the account associated with a quote.
A form-level warning works well when both entries can be valid on their own. A proposed discount of 12% needs review only because the threshold on this quote is 10%. Look under formContext.ui for the methods that display and clear a form notification.
For simpler requirements, check the business rule designer first. A maker can use a business rule to show a field when a condition is met. For this quote, JavaScript lets you give the warning its own identifier. The script can then clear the discount warning while leaving other messages visible.
For this hypothetical quote, add two custom decimal columns to the draft quote form. Name them Proposed Discount and Review Threshold. In both columns, 10 means 10%. In the script below, replace new_proposeddiscount and new_reviewthreshold with the logical names in your environment. Use the names from the Dataverse column definitions, including their publisher prefix.
function checkQuoteDiscount(executionContext) {
const form = executionContext.getFormContext();
const discount = form.getAttribute(“new_proposeddiscount”)?.getValue();
const threshold = form.getAttribute(“new_reviewthreshold”)?.getValue();
const warningId = “quote_discount_review”;
form.ui.clearFormNotification(warningId);
if (
typeof discount === “number” &&
typeof threshold === “number” &&
discount > threshold
) {
form.ui.setFormNotification(
“Discount exceeds the review threshold. You can save this draft for review.”,
“WARNING”,
warningId
);
}
}
The getValue() entry in the Client API reference Dynamics 365 shares with other model-driven apps explains the type checks. A decimal column returns a number when populated and null when blank. With a zero threshold, any positive discount triggers review. Testing if (threshold) would skip that case.
Save the function in a JavaScript web resource and publish it. Add the resource to the form libraries in the form designer. An event handler tells the app which function in that library to run. Register the same function, checkQuoteDiscount, on the form’s OnLoad event and on the OnChange event of each of the two columns. Select Pass execution context as first parameter for each registration, then save and publish the form.
Inside the function, executionContext.getFormContext() identifies the form where the event occurred. The load event covers an existing quote. The two change events cover edits to either side of the comparison. Raising the threshold can clear a warning even if the seller leaves the proposed discount untouched.
On a draft quote, set the review threshold to 10%. Enter a proposed discount of 12% and leave the field. The warning should appear. Reduce the discount to 10% and leave the field again. The warning should clear because the rule applies only when the discount exceeds the threshold.
Now leave the discount at 10% and lower the threshold to 8%. If the warning appeared in the first test but stays absent here, inspect the threshold column’s event registration. If the warning appears after an edit but is missing when you reopen an over-threshold quote, inspect the form’s load event.
If neither test produces a message, set a breakpoint on the function’s first line. If the breakpoint never fires, check the library and function name on the published form. An error at getFormContext() points to the setting that passes the execution context. Once execution reaches the comparison, inspect both values. Here, undefined means the script could not find the column on that form.
The seller can still save a draft with this warning. If a discount must be rejected across imports and integrations as well, a synchronous Dataverse plug-in can enforce that policy. Ebtechsol suggests asking a seller what they think they can do after reading the warning. If they think saving is blocked, the message needs work.
Find the function’s event registration. Microsoft recommends obtaining the form through executionContext.getFormContext() for new work. When updating an existing handler, check how it receives its context before replacing references to the deprecated Xrm.Page object.
Calling setValue() does not trigger the column’s change handlers. If all registered handlers should run after the update, call fireOnChange() on that attribute. Avoid calling it from a handler that would then trigger itself repeatedly.
Yes. During a column change event, executionContext.getEventSource().getName() returns the logical name of the changed column. That identifies which registration ran. The comparison still needs both values.
If the account’s threshold is absent from the quote form, Xrm.WebApi.retrieveRecord() can retrieve it using the account ID. Use $select to request the threshold column alone. The proposed discount still comes from the open quote so the comparison includes the seller’s latest edit.
Yes. Calling setNotification() on a supported field control blocks the form from saving. Place the error on a visible control the seller can correct, and clear it with clearNotification() once the value is valid.
Reuse the comparison, but adapt how you display the warning. A grid event can supply a row context. The Client API reference Dynamics 365 makers use for forms also lists the events and methods each grid type supports.
A column can appear in more than one place on a form. Getting one control by name targets a single instance. To update every bound control, iterate over the attribute’s controls collection.
Microsoft guarantees the context during the event that supplied it. If a delayed callback runs after the seller navigates away, the form may have changed. Capture the values needed for the calculation while the handler is running.
Call getIsDirty() on the discount attribute. It returns true when the current value differs from the last committed value the client retrieved. A saved discount can still require review.
A populated lookup returns an array, even when the seller can select only one customer. Read the first entry’s id and entityType to identify the record and its table. Check for an empty lookup before accessing the first entry.
Use Xrm.WebApi.online.execute (request) to call a Microsoft Dataverse custom API…
Sales confirms an order, then emails the warehouse a copy…
EB Technical Solutions FZE /
EB TECHNICAL SOLUTIONS (PVT.) LIMITED
Copyright © 2026 EBTECHSOL


Ask me anything about AI Automation, API Integration, SaaS Development or our Services.
Just get in touch via text or microphone.