Showing or Hiding Printables Based on a Value for the Selected Record in Creatio

Printables in Creatio show in the “Print” menu when viewing a record. In this article I will show you how to conditionally show or hide a specific printable in the print menu based on a value of the current record being viewed. The scenario we’ll use is that we have a printable called “Customer questionnaire” that we only want to show if the current contact has a Type value of “Customer”. The end result will look like this:

In the animated image above, notice that as we change from record to record that the “Customer questionnaire” shows or hides based on the Contact Type value.

To do this, we’ll actually need to add code to both the section *and* the edit page. When you’re viewing a record in “combined mode”, which is the mode when viewing a record by opening it in a section list, the items on top, such as the print menu, actually belong to the section – even though you’re viewing a contact. For this reason we’ll need to add our code to the section. You can tell when you’re in combined mode since you’ll see the option to pop out the list on the left side to click through records. When you open a contact from places such as the Contact’s detail on the account page, or from a Contact lookup somewhere, you’ll be in edit mode. Notice in these cases you can’t pop out the section list of contacts on the left side, that isn’t there. In this case, the items up top belong to the edit page. For this reason we’ll need to add our code to the edit page as well. For the most part, the code we’ll add to both the section and the edit page will be mostly the same, with some small differences. In cases like this, I usually try to reduce the duplicated code by using a mixinmodule, or the sandbox, but in this article, we’ll duplicate the code to keep things easily understood.

Code for ContactSectionV2

We’ll add the following code to the methods of the ContactSectionV2:

// since we'll be determining if the printable is viewable
// based on the Type column, we need to make sure that column
// is available in the section list query
initQueryColumns: function(esq) {
	this.callParent(arguments);
            
 	if (!esq.columns.contains("Type")) {
		esq.addColumn("Type");
	}
},
          
// now we need to wire up the Visible property of each menu item
// to our own function where we'll check the type column and return
// whether or not the printable should be shown
initCardPrintForms: function() {
	this.callParent(arguments);
              
	var printMenuItems = this.get(this.moduleCardPrintFormsCollectionName);
	if (Ext.isEmpty(printMenuItems)) return;
            	
	printMenuItems.each(function(item) {
		item.set("Visible", {bindTo: "getPrintMenuItemVisible"});
	}, this);
},
          
// this is the function will determine if a printable is visible
// it is called for each printable and will return true/false to show or hide
getPrintMenuItemVisible: function(reportId) {
	if (Ext.isEmpty(this.get("ActiveRow"))) return true;
              	
	var type = this.get("GridData").get(this.get("ActiveRow")).get("Type") || { displayName: "" },
	    printMenuItems = this.get(this.moduleCardPrintFormsCollectionName),
	    item = printMenuItems.find(reportId);
              
	if (Ext.isEmpty(item)) return;
                
	switch (item.get("Caption")) {
		case "Customer questionnaire":
			return type.displayValue === "Customer";
		default:
			return true;
	}
}

Now, we’ll add similar code to the edit page.

Code for ContactPageV2

Now add the following code to the contact edit page:

// we need to wire up the Visible property of each menu item
// to our own function where we'll check the type column and return
// whether or not the printable should be shown
initCardPrintForms: function() {
	this.callParent(arguments);
              
	var printMenuItems = this.get(this.moduleCardPrintFormsCollectionName);
	if (Ext.isEmpty(printMenuItems)) return;

	printMenuItems.each(function(item) {
		item.set("Visible", {bindTo: "getPrintMenuItemVisible"});
	}, this);
},
			
// this is the function will determine if a printable is visible
// it is called for each printable and will return true/false to show or hide
getPrintMenuItemVisible: function(reportId) {
	var type = this.get("Type") || { displayValue: "" },
	    printMenuItems = this.get(this.moduleCardPrintFormsCollectionName),
	    item = printMenuItems.find(reportId);
              
	if (Ext.isEmpty(item)) return;
              	
	switch (item.get("Caption")) {
		case "Customer questionnaire":
			return type.displayValue === "Customer";
		default:
			return true;
	}
}

That is it. It might seem like a lot, but ideally, we would reduce that duplicated code so we can reference the same code from both the section and the edit page.

ABOUT THE AUTHOR

Ryan Farley

Ryan Farley is the Director of Development for Customer FX and creator of slxdeveloper.com. He's been blogging regularly about SalesLogix, now Infor CRM, since 2001 and believes in sharing with the community. His new passion for CRM is Creatio, formerly bpm'online. He loves C#, Javascript, web development, open source, and Linux. He also loves his hobby as an amateur filmmaker.

Submit a Comment

Your email address will not be published. Required fields are marked *

Subscribe To Our Newsletter

Join our mailing list to receive the latest Infor CRM (Saleslogix) and Creatio (bpm'online) news and product updates!

You have Successfully Subscribed!