Difference between two dates extracted by Audit API is not viewing.

Showing results for 
Search instead for 
Did you mean: 
Active Member II

Difference between two dates extracted by Audit API is not viewing.

Hello everyone, 

I am working on an Audit Report requested by my client. I am getting entries of users Login and Logout time but I also want how much time he spent when the user was logged in. So I simply subtracted my login time and logout and stored it in a variable in my javascript controller of my webscript. 

The problem is the subtracted date and time is not appearing on Alfresco. Instead there is symbol appearing on my report. 

Have a look at my js code, you may get an idea of what im trying to do.

var auditJSON = {}
var connector= remote.connect("alfresco-api");
var user = page.url.args["user"];
//var result = connector.get("/-default-/public/alfresco/versions/1/audit-applications/alfresco-access/audit-entries?skipCount=0&maxItems=1000&where=(createdByUser=" + user +"%20and%20valuesKey='/alfresco-access/login/user')&include=values'");
var result = connector.get("/-default-/public/alfresco/versions/1/audit-applications/alfresco-access/audit-entries?skipCount=0&maxItems=1000000&where=(createdByUser="+ user +"%20and%20createdAt%20BETWEEN%20('2020-12-01T12%3A13%3A51.593%2B01%3A00'%20%2C%20'2021-04-25T10%3A05%3A16.536%2B01%3A00'))&include=values");
var final_results = [];
if (result.status.code == status.STATUS_OK) {
    var auditJSON = jsonUtils.toObject(result);
var entries = auditJSON["list"]["entries"];
model.user= user;
var map = {}
var activities = "";
var login_date;
var logout_date;
var map_key = "";
var results = [];
var result = {};
for(var i = 0; i < entries.length; i++){
        var values = entries[i].entry.values;
    if(values["/alfresco-access/login/user"] != null){
        activities = "";
        login_date = entries[i].entry.createdAt;
    } else if (values["/alfresco-access/logout/user"] != null){
        logout_date = entries[i].entry.createdAt;
        map_key = login_date + "-" + logout_date + "-" + user;
        map[map_key] = activities;
         var time_elapsed = (new Date(logout_date).getTime() - new Date(login_date).getTime())/1000/60/60;
             time_elapsed = Math.round(time_elapsed * 100);
	     time_elapsed = time_elapsed / 100;
        result = {login_date: login_date, logout_date: logout_date, user: user, activities: activities, time_elapsed: time_elapsed}
        activities = "";
    } else {
        activities += values["/alfresco-access/transaction/action"] + "\n" + "\n" + values["/alfresco-access/transaction/path"] + "\n" + "\n";
        activities = activities.replace("/app:company_home","").replace("st:sites","Sites").replace("/cm:","/").replace("/sys:system/sys:people","User");

model.results = results;

Now as you can see the difference between login and logout is stored in "time_elapsed" variable.

But when I view my report a symbol is appearing instead. Take a look at the report.Screenshot from 2021-04-22 04-18-25.png

As you can see in the end of  every row there is this symbol appearing.

I calculated the difference of the same datetime format in an onlne js editor and the result is printing fine their. But the output is not printing on Alfresco. 

Any idea how this problem can be solved?

1 Reply
Community Manager
Community Manager

Re: Difference between two dates extracted by Audit API is not viewing.

Hi @Syedjunaid 

Can you:

1) show us the actual value that you expect to be displayed

2) print the value to the log output - how does it appear there?


Digital Community Manager, Alfresco Software.
Problem solved? Click Accept as Solution!