Sunday, January 18, 2015

Setting Field Visibility when the Business Process Stage Changes

In Dynamics 2015 we can now hook into the OnStageChange event which gets fired when the stage of a business process flow changes. We do this by adding an event handler to the OnStageChange event when the form loads. In this example when the form loads it calls the AddStageHandlers function so that the StageChangedHandler function gets called when the stage changes.

Dynamics CRM Form

When the StageChangedHandler function runs it checks if the opportunity is at the "Close" stage. If the stage is Close then the header field estimated value field is disabled so that the Estimated Revenue cannot changed. It also hides the purchase timeframe field.

  1. function AddStageHandlers() {
  3. }
  5. function StageChangedHandler() {
  6.     var activeStage =;
  7.     var stageName = activeStage.getName();
  8.     if (stageName == "Close") {
  9.         Xrm.Page.ui.controls.get("purchasetimeframe").setVisible(false);
  10.         Xrm.Page.ui.controls.get("header_estimatedvalue").setDisabled(true);
  11.     }
  12. }

Dynamics CRM Opportunity

No comments:

Post a Comment