Hello Community, 

 

I have requirements to show How much time has passed till case has been registered in the system. 

 

But the real catch is, the information I have to show on Section list like shown as below.

Here I want to add Passed time column near Resolution time. 

Passed time is time passed till registration of Case. 

 

And also, I want to do same on Dashboard’s list view.

Like 0

Like

1 comments

Hello Meet,

 

Here is an example of how I did it on my side:

 

1) Create a button in the CaseSection schema:

{
					"operation": "insert",
					"name": "CustomButtonContainer",
					"parentName": "ActionButtonsContainer",
					"propertyName": "items",
					"values": {
						"itemType": Terrasoft.ViewItemType.CONTAINER,
						"items": []
					}
 
				},
				{
					"operation":"insert",
					"name": "RecalculateTimeSpent",
					"parentName": "CustomButtonContainer",
					"propertyName": "items",
					"values": {
						"itemType": Terrasoft.ViewItemType.BUTTON,
						"caption": {bindTo: "Resources.Strings.RecalculateTimeSpentButtonCaption"},
						"click": {bindTo: "updateCaseTimePassed"},
						"style": Terrasoft.controls.ButtonEnums.style.RED
					}
				}

As a result the button will appear in the section:

Also don't forget to add the localizable value with "RecalculateTimeSpentButtonCaption" caption.

 

2) Create a string column in the "Case" object with "UsrTimePassedFromCreation" code and Text (250 characters) data type. Save and publish the object.

 

3) Display this created string column in the "Cases" section.

 

4) Add these methods to the CaseSection schema:

updateCaseTimePassed: function(){
				const today = new Date();
				for (let i = 0; i<this.get("GridData").collection.items.length;i++){
					let recordId = this.get("GridData").collection.items[i].values.Id;
    				let result = (today - this.get("GridData").get(recordId).get("CreatedOn")).toString(); //ms
					let diffDays = Math.floor(result / 86400000); //days
					let diffHrs = Math.floor((result % 86400000) / 3600000); // hours
					let diffMins = Math.round(((result % 86400000) % 3600000) / 60000); // minutes
					let resultMessage = diffDays + " days " + diffHrs + " hours " + diffMins + " minutes";
					let updateQuery = Ext.create("Terrasoft.UpdateQuery", {
							rootSchemaName: "Case"
						});
						let filters = updateQuery.filters;
						let caseIdFilter = updateQuery.createColumnFilterWithParameter(Terrasoft.ComparisonType.EQUAL,
								"Id", recordId);
						filters.add("caseIdFilter", caseIdFilter);
						updateQuery.setParameterValue("UsrTimePassedFromCreation", resultMessage, Terrasoft.DataValueType.TEXT);
						updateQuery.execute();
				}
				this.sleep(2000);
				this.updateSection();
			},
			sleep: function(milliseconds) {
  				const date = Date.now();
  				let currentDate = null;
  					do {
    					currentDate = Date.now();
  					} while (currentDate - date < milliseconds);
			}

5) Refresh the page and check the result - the values should populate for all records in the grid upon clicking the added button:

So you will periodically need to click the button to update information on the case time spent. Also you can add additional check for the case status so not to update records that are in "Resolved" or "Closed" status or you can build a filter with cases that are in the "In progress" status and use the button on them only.

 

Also please note that since the data is updated in the database directly you will see the same data in any dashboard representing cases.

 

Best regards,

Oscar

Show all comments

Hi Community,

Form this post, (https://community.creatio.com/questions/button-section-page-particular-column) I have managed also to put buttons on each record in section page. Now i need also to do the same on LIST type Dashboard. Any idea how can I do this?

 

Like 0

Like

1 comments

Dear Fulgen, 



I don't have an exact example of how to do it. Here is the way how you can override the dashboard: 

1) Create your custom module that would extend Terrasoft.DashboardListedGridViewModel

Here is an example: 

define("UsrDashboardListedGridViewModel", ["ControlGridModule"], function() {

    Ext.define("Terrasoft.UsrDashboardListedGridViewModel", {

        extend: "Terrasoft.DashboardListedGridViewModel",

        

        getGridDataColumns: function() {

            var gridDataColumns = this.callParent(arguments);

            gridDataColumns.QualifyStatus = gridDataColumns.QualifyStatus || {path: "QualifyStatus"};

            gridDataColumns.QualificationProcessId =

                    gridDataColumns.QualificationProcessId || {path: "QualificationProcessId"};

            gridDataColumns["QualifyStatus.StageNumber"] =

                    gridDataColumns["QualifyStatus.StageNumber"] || {path: "QualifyStatus.StageNumber"};

            return gridDataColumns;

        },

        getQualifyStatus:function(id) {

            var activeRow;

            if (id) {

                var gridData = this.getGridData();

                activeRow = gridData.get(id);

            } else {

                activeRow = this.getActiveRow();

            }

            if (!activeRow) {

                return null;

            }

            var qualifyStatus = activeRow.get("QualifyStatus");

            return (qualifyStatus) ? qualifyStatus.value : null;

        },

        addColumnLink: function(item) {

            item.getQualifyStatusValue = function(qualifyStatus) {

                if (!qualifyStatus) {

                    return null;

                } else {

                    return {

                        value: qualifyStatus && qualifyStatus.StageNumber || this.get("QualifyStatus.StageNumber"),

                        displayValue: qualifyStatus.displayValue

                    };

                }

            };

            return this.callParent(arguments);

        },

        applyControlConfig: function(control) {

            control.config = {

                className: "Terrasoft.BaseProgressBar",

                value: {

                    "bindTo": "QualifyStatus",

                    "bindConfig": {"converter": "getQualifyStatusValue"}

                },

                width: "158px"

            };

        }

    });

    return {};

});

2) Create your custom module that would extend Terrasoft.DashboardListedGridViewConfig

Example: 

define("UsrDashboardListedGridViewConfig", ["UsrControlGridModule"], function() {

    Ext.define("Terrasoft.UsrDashboardListedGridViewConfig", {

        extend: "Terrasoft.DashboardListedGridViewConfig",



        generate: function() {

            var config = this.callParent(arguments);

            config.items[1].className = "Terrasoft.UsrControlGrid";

            config.items[1].controlColumnName = "QualifyStatus";

            config.items[1].applyControlConfig = { bindTo: "applyControlConfig" };

            return config;

        }

        

    });

    return {};

});

3) Create you custom module to override Terrasoft.DashboardGridModule: 

define("UsrDashboardGridModule", ["UsrDashboardListedGridViewModel", "UsrDashboardListedGridViewConfig"], function() {



    Ext.define("Terrasoft.configuration.UsrDashboardGridModule", {

        alternateClassName: "Terrasoft.UsrDashboardGridModule",

        override: "Terrasoft.DashboardGridModule",



        viewModelClassName: "Terrasoft.UsrDashboardListedGridViewModel",



        viewConfigClassName: "Terrasoft.UsrDashboardListedGridViewConfig"



    });



});

4) Create your DashboardGridModuleWrapper, which enables UsrDashboardGridModule : 

define("UsrDashboardGridModuleWrapper", ["BaseModule"], function() {



    Ext.define("Terrasoft.configuration.UsrDashboardGridModuleWrapper", {

        extend: "Terrasoft.BaseModule",

        alternateClassName: "Terrasoft.UsrDashboardGridModuleWrapper",



        constructor: function() {

            var parentMethod = this.getParentMethod(this, arguments);

            Terrasoft.require(["DashboardGridModule"], function() {

                Terrasoft.require(["UsrDashboardGridModule"], parentMethod, this);

            }, this);

        }



    });

    return Ext.create("Terrasoft.UsrDashboardGridModuleWrapper");



});

5) Override BootstrapModulesV2 and add DashboardGridModuleWrapper to the dependencies: 

define("BootstrapModulesV2", ["UsrDashboardGridModuleWrapper"], function() {

    return {};

});



You can use this idea to implement the logic from the article you've mentioned to the list dashboard. 

Show all comments