There is a requirement in which I have to make printable visible on the basis of data in the connected object. I followed this article https://customerfx.com/article/showing-or-hiding-printables-based-on-a-value-for-the-selected-record-in-creatio/.
It is working fine on the combined mode in edit page and only showing printable which is matching with the condition, but the same is not reflecting on the separate mode in edit page and showing the complete list of printable.
Is there something which I am missing or any other workaround ?
Methods which I have added on section is :
initQueryColumns: function(esq) {
this.callParent(arguments);
if (!esq.columns.contains("Id")) {
esq.addColumn("Id");
}
},
GetDocumentCollection: function() {
var recObj = [];
var id = this.get("GridData").get(this.get("ActiveRow")).get("Id");
var esq = Ext.create("Terrasoft.EntitySchemaQuery", { rootSchemaName: "Document" });
esq.addColumn("UsrDocumentName.Name");
esq.filters.add("UsrTransactions", Terrasoft.createColumnFilterWithParameter(
Terrasoft.ComparisonType.EQUAL, "UsrTransaction", id));
esq.getEntityCollection(function(result) {
var response = result.collection;
var hasRecord = (response.collection.length !== 0);
if(hasRecord) {
result.collection.each(function(item) {
recObj.push(item.get("UsrDocumentName.Name"));
});
}
this.set("DocumentCollection",recObj);
}, this);
},
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 Id = this.get("GridData").get(this.get("ActiveRow")).get("Id"),
printMenuItems = this.get(this.moduleCardPrintFormsCollectionName),
item = printMenuItems.find(reportId);
this.GetDocumentCollection();
if (Ext.isEmpty(item)) return;
var ReportName = item.get("Caption");
var DocCollection = this.get("DocumentCollection");
if(DocCollection === undefined){
return false;
}
else{
if(DocCollection.includes(ReportName)){return true;}
else{return false;}
}
}
Methods which I have added on edit page is :
GetDocumentCollection: function() {
var recObj = [];
var id = this.get("Id");
var esq = Ext.create("Terrasoft.EntitySchemaQuery", { rootSchemaName: "Document" });
esq.addColumn("UsrDocumentName.Name");
esq.filters.add("UsrTransactions", Terrasoft.createColumnFilterWithParameter(
Terrasoft.ComparisonType.EQUAL, "UsrTransaction", id));
esq.getEntityCollection(function(result) {
var response = result.collection;
var hasRecord = (response.collection.length !== 0);
if(hasRecord) {
result.collection.each(function(item) {
recObj.push(item.get("UsrDocumentName.Name"));
});
}
this.set("DocumentCollection",recObj);
}, this);
},
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) {
//this.GetDocumentCollection();
var Id = this.get("Id"),
printMenuItems = this.get(this.moduleCardPrintFormsCollectionName),
item = printMenuItems.find(reportId);
if (Ext.isEmpty(item)) return;
this.GetDocumentCollection();
var ReportName = item.get("Caption");
var DocCollection = this.get("DocumentCollection");
if(DocCollection === undefined){
return false;
}
else{
if(DocCollection.includes(ReportName)){return true;}
else{return false;}
}
}
Like
Hello,
In order to filter printables in edit mode, both in your page and section replacing schemas, you need to replace a method preparePrintFormsMenuCollection. Inside this method, you should leave base method as is (the code before and after comments below), and only change the code between the comments to create the logic that fits your business needs:
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" }); } //Here is your logic for filtering of printables /*************************************************************************/ /* YOUR CODE, for example var currentState = this.get("State"); var currentStateDisplayValue = currentState.displayValue; var currentStateDisplayValueToLower = currentStateDisplayValue?.toLowerCase(); var isStateEmpty = Ext.isEmpty(currentState); if (!isStateEmpty && currentStateDisplayValue && item.get("Caption").includes(currentStateDisplayValueToLower)) { item.set("Visible", true); } else { item.set("Visible", false); } */ /*************************************************************************/ }, this); }