Article

Show different printables in Print menu for different opportunity stages

Case description:

We want to show different printables for different opportunity stages.

Algorithm of realization:

  1.  Create replacing client modules for OpportunityPageV2 and OpportunitySectionV2.
  2. Add message that will refresh print button when we work in CombinedMode and add event handler which run when opportunity stage was changed.
    1. OpportunityPageV2

      define("OpportunityPageV2", ["SysModuleReport"], function (SysModuleReport) {
          return {
              entitySchemaName: "Opportunity",
              details: /**SCHEMA_DETAILS*/{}/**SCHEMA_DETAILS*/,
              attributes: {
                  "Stage": {
                      "onChange": "onStageChanged"
                  }
              },
              messages: {
                  "PrintButtonFilterMessage": {
                      mode: Terrasoft.MessageMode.PTP,
                      direction: Terrasoft.MessageDirectionType.PUBLISH
                  }
              },
              methods: {
                  printButtonFilterPublishMessage: function () {
                      return this.sandbox.publish("PrintButtonFilterMessage", this.get("Stage").value, ["key"]);
                  },
                  onStageChanged: function () {
                      this.printButtonFilterPublishMessage();
                  }
              },
              diff: /**SCHEMA_DIFF*/[]/**SCHEMA_DIFF*/,
              rules: {},
              businessRules: /**SCHEMA_BUSINESS_RULES*/{}/**SCHEMA_BUSINESS_RULES*/
          };
      });

       

    2. OpportunitySectionV2

      define("OpportunitySectionV2", [], function () {
          return {
              messages: {
                  "PrintButtonFilterMessage": {
                      mode: Terrasoft.MessageMode.PTP,
                      direction: Terrasoft.MessageDirectionType.SUBSCRIBE
                  }
              },
              methods: {
                  init: function () {
                      this.callParent(arguments);
                      this.sandbox.subscribe("PrintButtonFilterMessage", this.onPrintButtonFilterMessage, this, ["key"]);
                  },
                  onPrintButtonFilterMessage: function (args) {
                      this.set("StageId", args);
                  }
              },
              diff: []
          };
      });

       

  3. Override preparePrintFormsMenuCollection method in both pages and add calling of initCardPrintForms() and initSectionPrintForms() on stage changing and PrintButtonFilterMessage handling.
    1. OpportunityPageV2 

      define("OpportunityPageV2", ["SysModuleReport"], function (SysModuleReport) {
          return {
              entitySchemaName: "Opportunity",
              details: /**SCHEMA_DETAILS*/{}/**SCHEMA_DETAILS*/,
              attributes: {
                  "Stage": {
                      "onChange": "onStageChanged"
                  }
              },
              messages: {
                  "PrintButtonFilterMessage": {
                      mode: Terrasoft.MessageMode.PTP,
                      direction: Terrasoft.MessageDirectionType.PUBLISH
                  }
              },
              methods: {
                  preparePrintFormsMenuCollection: function (printForms) {
                      var stage = this.get("Stage");
                      printForms.eachKey(function (key, item) {
                          if (!item.get("Caption")) {
                              item.set("Caption", item.get("NonLocalizedCaption"));
                          }
                          item.set("Tag", key);
                          if (item.get("TypeColumnValue")) {
                              item.set("Visible", { bindTo: "getPrintMenuItemVisible" });
                          }
                          //Here is your logic for filtering of printables
                          /*************************************************************************/
                          if (stage !== undefined) {
                              if (stage.value === "423774cb-5ae6-df11-971b-001d60e938c6") {
                                  if (key === "0d8c28ce-9794-42be-8427-3d5d60e60c1f") {
                                      item.set("Visible", false);
                                  }
                                  else {
                                      item.set("Visible", true);
                                  }
                              } else if (stage.value === "fb563df2-5ae6-df11-971b-001d60e938c6") {
                                  if (key === "c80094c5-2513-4857-b5da-4b355aed8c10") {
                                      item.set("Visible", false);
                                  }
                                  else {
                                      item.set("Visible", true);
                                  }
                              } else {
                                  item.set("Visible", true);
                              }
                          }
                          /*************************************************************************/
                      }, this);
                  },
                  printButtonFilterPublishMessage: function () {
                      return this.sandbox.publish("PrintButtonFilterMessage", this.get("Stage").value, ["key"]);
                  },
                  onStageChanged: function () {
                      this.initCardPrintForms();
                      this.printButtonFilterPublishMessage();
                  }
              },
              diff: /**SCHEMA_DIFF*/[]/**SCHEMA_DIFF*/,
              rules: {},
              businessRules: /**SCHEMA_BUSINESS_RULES*/{}/**SCHEMA_BUSINESS_RULES*/
          };
      });

       

    2. OpportunitySectionV2

      define("OpportunitySectionV2", [], function() {
          return {
              messages: {
                  "PrintButtonFilterMessage": {
                      mode: Terrasoft.MessageMode.PTP,
                      direction: Terrasoft.MessageDirectionType.SUBSCRIBE
                  }
              },
              methods: {
                  preparePrintFormsMenuCollection: function(printForms) {
                      printForms.eachKey(function(key, item) {
                          if (!item.get("Caption")) {
                              item.set("Caption", item.get("NonLocalizedCaption"));
                          }
                          item.set("Tag", key);
                          if (item.get("TypeColumnValue")) {
                              item.set("Visible", {bindTo: "getPrintMenuItemVisible"});
                          }
                          //Here is your logic for filtering of printables
                          /*************************************************************************/
                          if (this.get("StageId") !== undefined) {
                              if (this.get("StageId") === "423774cb-5ae6-df11-971b-001d60e938c6") {
                                  if (key === "0d8c28ce-9794-42be-8427-3d5d60e60c1f") {
                                      item.set("Visible", false);
                                  }
                                  else {
                                      item.set("Visible", true);
                                  }
                              } else if (this.get("StageId") === "fb563df2-5ae6-df11-971b-001d60e938c6") {
                                  if (key === "c80094c5-2513-4857-b5da-4b355aed8c10") {
                                      item.set("Visible", false);
                                  }
                                  else {
                                      item.set("Visible", true);
                                  }
                              } else {
                                  item.set("Visible", true);
                              }
                          }
                          /*************************************************************************/
                      }, this);
                  },
                  init: function() {
                      this.callParent(arguments);
                      this.sandbox.subscribe("PrintButtonFilterMessage", this.onPrintButtonFilterMessage, this, ["key"]);
                  },
                  onPrintButtonFilterMessage: function(args) {
                      this.set("StageId", args);
                      this.initSectionPrintForms();
                      this.initCardPrintForms();
                  }
              },
              diff: []
          };
      });

      !!!IMPORTANT!!! - in preparePrintFormsMenuCollection() you can change code only between comments

      Identificators of printables you can get from SysModuleReport table in you DB

Like 0

Like

Share

1 comments

Hi Tatiana Rogova,

       This solution doesn't work in section, because the function preparePrintFormsMenuCollection can't get stage value to check. Please double check and update your solution.

Thanks

Toàn Mai

Show all comments