printable filter doesn't apply when record page is refreshed

Hello creatio team, 

I have successfully set up the printables show/hide feature based on the value from field(Currency). But it only works when record is opened from section page or navigated from other page. It doesn't work if I refresh the record page. (I don't have any section printable so only focusing on edit page printables. )

 I have tried adding the preparePrintFormsMenuCollection() on the edit page and apply the filter there so it could work on refresh. But the value of the currency field coming as undefined so I can apply static filter and that worked on refresh but if I want to add condition based on currency to show and hide I can't do it.

My code on Edit page: 

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 currentCurrency = this.get("UsrCurrency") || { displayValue: "" };

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

var isUsCurrency = currentCurrency.displayValue === "US";

var containsUs = caption.includes("-US");

return isUsCurrency === containsUs;

}, 

My code on section page: 

initQueryColumns: function(esq) {

this.callParent(arguments);

if (!esq.columns.contains("UsrCurrency")) {

esq.addColumn("UsrCurrency");

}

},

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

if (Ext.isEmpty(this.get("ActiveRow"))) return true;

var currentCurrency = this.get("GridData").get(this.get("ActiveRow")).get("UsrCurrency") || { displayValue: "" };

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

var        item = printMenuItems.find(reportId);

if (Ext.isEmpty(item)) return;

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

var isUsCurrency = currentCurrency.displayValue === "US";

var containsUs = caption.includes("-US");

return isUsCurrency === containsUs;

},

I have tried adding in the  preparePrintFormsMenuCollection()

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("## currentCurrency", currentCurrency);

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

If(currentCurrency.displayValue === "US"){

item.set("Visible", caption.includes("-US"));

}

}, this);

}

Like 0

Like

5 comments

The reason why this happens is when you open a page from the section you are in combined mode and the logic for the print menu comes from the Section schema. When you refresh, the edit page only opens in edit mode, in this case the logic is coming from the Page schema (when you refresh, note that the tab on the left to popout the section list to navigate is no longer there). Basically, your logic needs to be implemented on both the section schema and also on the page schema to handle both cases. There are a few community posts on this that show both sides, perhaps this or this might help to piece together the details.

Ryan

Ryan Farley,

Hello Ryan, highly appreciate your response. As I have attached above, I have included the code on edit page as well. Seems like edit page code doesn't work. I have exactly similar code as your article but edit page code doesn't apply the filter. I see couple of person commented on below the article and they are facing the same issue. Did we find the work around yet?

Hello Creatio support do we have solution for this?

The problem here is that on Edit page initCardPrintForms method is called before onEntityInitialized so the field value is undefined because it hasn't been initialized yet. It's the known issue and we have already registered a request to our R&D team to address that.

Iryna Oriyenko,

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? 

Show all comments