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.