Question

Printable visibility based on lookup value

Hi all,

 

There is a requirement in which I have to make printable visible on the basis of selected lookup. 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 edit page and only showing printable which is matching with the condition, but the same is not reflecting on the section and showing the complete list of printable.

Method which I have added on section and edit page is : 

methods: {

initQueryColumns: function(esq) {

    this.callParent(arguments);

 

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

        esq.addColumn("UsrDocumentRepositorySubtype");

    }

},

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 type = this.get("GridData").get(this.get("ActiveRow")).get("UsrDocumentRepositorySubtype") || { displayName: "" },

        printMenuItems = this.get(this.moduleCardPrintFormsCollectionName),

        item = printMenuItems.find(reportId);

 

    if (Ext.isEmpty(item)) return;

 

    switch (item.get("Caption")) {

         case "Mining and Quarrying Questionnaire":

            return type.displayValue === "Mining and Quarrying Questionnaire";

case "Alcohol Questionnaire":

            return type.displayValue === "Alcohol Questionnaire";

        default:

            return true;

    }

}

}

 

Output (Edit Page)

 

Output (Section)

 

Is there something which I am missing or any other workaround ?

 

Like 0

Like

5 comments

Hello,

 

In the section you need to use the approach like below:

			rowSelected: function(primaryColumnValue) {
				this.callParent(arguments);
				var row = this.getGridData().get(primaryColumnValue);
				var reportCollection = this.get(this.moduleSectionPrintFormsCollectionName);
				var usrDocumentRepositorySubType = row.get("UsrDocumentRepositorySubtype");
				var isUsrDocumentRepositorySubTypeEmpty = Ext.isEmpty(usrDocumentRepositorySubType);
				Terrasoft.each(reportCollection, function(report) {
					if (!isUsrDocumentRepositorySubTypeEmpty && usrDocumentRepositorySubType.displayValue == "Mining and Quarrying Questionnaire" && report.get("Caption") == "Mining and Quarrying Questionnaire") {
						report.set("Visible", true);
					}
					else {
						report.set("Visible", false);
					}
				}, this);
			}

This is an example for only "Mining and Quarrying Questionnaire", additional check should be also applied for the "Alcohol Questionnaire". Using this approach after refreshing the page correct reports started to show on the section list.

Hi Oleg,

 

Thank you for the response. Now it is working fine for the section and while creating record.

But, when I open any saved record, it is showing complete list of printable.

 

Method which I have added on Edit Page Schema is :

 

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("UsrDocumentRepositorySubtype") || { displayValue: "" },
        printMenuItems = this.get(this.moduleCardPrintFormsCollectionName),
        item = printMenuItems.find(reportId);
               
    if (Ext.isEmpty(item)) return;
                 
    switch (item.get("Caption")) {
        case "Mining and Quarrying Questionnaire":
            return type.displayValue === "Mining and Quarrying Questionnaire";

       case "Gliding Questionnaire":
            return type.displayValue === "Gliding Questionnaire";
        
        default:
            return true;
    }

 

Please help.

Prashant Jha,

Hi Prashant

 

Did you ever resolve this issue as I have the same problem

 

regards

Rob Watson,

Hi Rob, 
Did you find any solution to resolve this. Even I face the same issue

Thanks in advance

Hello all,

 

The example from my previous post should be modified to make it work when opening the page from the section. This time I performed the test using ContractSectionV2 with 2 reports: Contract approval and Contract draft:

The logic will be: if status of a contract is "Approval" - show only "Contract approval" report, if status is "Draft" - show only "Contract draft" report, otherwise show nothing (but for the record that is being created - show everything).

 

This can be achieved using this method added to the ContractSectionV2 schema:

rowSelected: function(primaryColumnValue) {
				this.callParent(arguments);
				var row = this.getGridData().get(primaryColumnValue);
				var getSelectedRowState = row.get("State");
				var selectedRowState = getSelectedRowState.displayValue;
				var selectedRowStateForCheck = selectedRowState?.toLowerCase();
				var reportCollection = this.get(this.moduleSectionPrintFormsCollectionName);
				var cardReportCollection = this.get(this.moduleCardPrintFormsCollectionName);
				var isStateEmpty = Ext.isEmpty(getSelectedRowState);
				Terrasoft.each(reportCollection, function(report) {
					if (!isStateEmpty && selectedRowStateForCheck && report.get("Caption").includes(selectedRowStateForCheck)) {
						report.set("Visible", true);
					}
					else {
						report.set("Visible", false);
					}
				}, this);
				Terrasoft.each(cardReportCollection, function(report) {
					if (!isStateEmpty && selectedRowStateForCheck && report.get("Caption").includes(selectedRowStateForCheck)) {
						report.set("Visible", true);
					}
					else {
						report.set("Visible", false);
					}
				}, this);
			}

The "State" column should be displayed in the section list and this is the code for the "Status" column of the contract. As a result:

 

1) Filtration in the section:

2) Filtration on the page opened from the section (for filtration on the page when refreshing the opened Contract page you need to do everything that is specified by Ryan here (part about ContactPageV2) (it happens because of the combined mode)):

3) For records in other statuses nothing will be shown in the list of the "Print" button (both in the section and on the page).

 

All you need to do is study this code and change the column to the one you will use on your page and don't forget to display this column in the section list.

Show all comments