Add calculated column in Section list's table and Dashboard table

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