show/ hide printables based on field value

Hello creatio experts, 

 

I want to show/ hide printables based on currency field. If the currency is us then show the printable which names contains '-US' in them. I have tried follow this article but the field value is getting undefined as the time this function run entity might not be initialized. I mainly want to do this for edit page.  

 

My code: 

 

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);

},

 

getPrintMenuItemVisible: function(reportId) {

var type = this.get("UsrCurrency") || { displayValue: "" },

console.log("## UsrCurrency", UsrCurrency);

var printMenuItems = this.get(this.moduleCardPrintFormsCollectionName),

item = printMenuItems.find(reportId);

if (Ext.isEmpty(item)) {

return false; // Ensure a boolean return

}                                

                                 var caption = item.get("Caption") || "";

 

return type.displayValue === "US Dollar" ? caption.includes("-US") : true;

},

 

Alternatively, I have tried this but printforms and currency come undefined

 

 

        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" });

               }

               var currentCurrency = this.get("UsrCurrency");

               console.log("## currentCurrency1", currentCurrency);

               var isCurrencyEmpty = Ext.isEmpty(currentCurrency);

               var currentCurrencyDisplayValue = isCurrencyEmpty ? "" : currentCurrency.displayValue || "";

               if (!isCurrencyEmpty && currentCurrencyDisplayValue=="US Dollar" && item.get("Caption").includes("-US")){

               item.set("Visible", true);

               }

               else {

               item.set("Visible", false);

               }

           

           }, this);

       },

 

We already have getModulePrintFormsESQ() on the edit page and if add filter there for currency it would hide the remaining printable in list but this function only responsible for creating query so this doesn't refresh the list of printables as value of currency is undefined at the first call.

Like 0

Like

3 comments

Hello Tony,

 

The logic of forming the list of reports that are displayed in the "Print" button added to the page is hardcoded in the _generateMenuItems method in the core Angular files of the app. It doesn't contain the "visible" property and selects printables for the current entity only once when the page is refreshed or the entity is opened and then forms an array of printables using filter.map chain and return this array for the button. And we cannot override the logic of the _generateMenuItems method.

 

So in order to hide printables you have to add the filters like that:


 

initCardPrintFormsEsqFilters: function(esq) {
	esq.filters.addItem(Terrasoft.createColumnFilterWithParameter(Terrasoft.ComparisonType.CONTAIN,
	"Caption",
	"testStringValue"));
}

 

The problem here is that initCardPrintFormsEsqFilters method is called before onEntityInitialized so the record fields are not initialized yet so their values are undefined.

 

Meanwhile we will create a request for our R&D team to implement the possibility of filtration button options using custom handlers and also possibility of filtration of printables list also using a custom handler.

 

Thank you for reporting this idea to us and helping us in making the app better!

Iryna Oriyenko,

Relying same text here for future refrences: 

 

Thank you for the response but isn't really there a way to reload or refresh the print records after the entity has been initialized? 

Currently the printables are selected only once when the page is refreshed or the entity is opened. Other changes that are made to printables later in the page life cycle (e.g. adding filters) will not have the effect and the printables list will remain the same as it was created during the initialization.

Show all comments