
When using a printable in Creatio on a record page, you might want to control when the printable can be run based on conditions such as whether the data is complete on the record. This is an easy task by overriding a function that exists on the page. Note, this method can be used to validate the record or for other purposes such as to control who can run a particular printable.
The print menu itself, along with the capability to run a printable, is added to a page via the PrintReportUtilities mixin. When an item is clicked on the Print menu, it executes a function on the page called generateCardPrintForm (added from the mixin). To override what happens when a printable is clicked from the print menu, all we need to do is override that function and then pass along to the function parent when/if we want to allow the actual print to occur.
For the scenario of this article, we will be controlling whether a printable named “Account contract” can be printed unless all required data that we need in the printable is completed on the record. The end result will look like this:
This is what our code will look like:
generateCardPrintForm: function(tag) { // first get the printable being accessed var printFormsCollection = this.get(this.moduleCardPrintFormsCollectionName), printForm = printFormsCollection.get(tag); // check if this is the printable we want to validate before use if (printForm.values.Caption === "Account contract") { var dueDate = this.get("UsrDue"); // check if the record is complete if (Ext.isEmpty(dueDate)) { var msg = "The following missing information must be added before the contract can be generated:\r\n\r\n"; msg += " - Due date\r\n"; Terrasoft.showInformation(msg); return; } // record is complete, allow print this.callParent(arguments); } else { // this was not the printable we need to validate, allow print this.callParent(arguments); } }
All we need to do here is get a reference to the actual form being printed. The function receives a tag, which is the Id of the printable itself. We’ll use that to get the printable details from the collection that stores all the printables displayed in the print menu. Then we can check to see if it is the printable we want to validate before using. When/if we want to allow the print to continue, we simply call the parent function using this.callParent(arguments) which allows things to continue normally.
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!