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.