Mitch’s Minute: Customizing the Opportunity Close form

Here is a deep dive into customizing the Opportunity Close form, including using JavaScript to manipulate data and change the Competitor field availability on Closed as Won.

Additional information about the process may be found in this Microsoft article: Customize the Opportunity Close form

Sample Code

  • On Closed as Won, enables the user to edit the Competitor field
  • On Closed as Lost, removes the Cancelled Status Reason.
function form_onLoad(executionContext) {
    var formContext = executionContext.getFormContext();
    const OpportunityState = {
        Open: 0,
        Won: 1,
        Lost: 2
    var opportunityStateCode = formContext.getAttribute("opportunitystatecode").getValue();
    // If the Opportunity is closing as Won,
    // then enable the Competitor field so we know who 
    // we won against
    if (opportunityStateCode === OpportunityState.Won) {
    // If the Opportunity is closing as Lost, 
    // then remove the Cancelled Status Reason
    if (opportunityStateCode === OpportunityState.Lost) {
        var cancelled = 4;

Leave a Reply 0 comments