Reports

spectura77
Tera Contributor

How to create a report with no. of times each user logged in last 30 days

 

What i have done so far is :

spectura77_0-1706192611470.pngspectura77_1-1706192691115.png

But i need to show number of times each user logged in last 30 days, Please guide!!

 

Thanks!!

4 REPLIES 4

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @spectura77 

 

check here 

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0749943

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

AndersBGS
Tera Patron
Tera Patron

Hi @spectura77 ,

 

I would create a custom table to capture the login timestamp and the user, and then build a report of that. Every time a user logins, there will be created a entry in sysevent. 

 

So basic, utilize the article utilized by Adam Stout, and then modify it towards sysevent table with name "login".

 

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.

 

Best regards

Anders

If my answer has helped with your question, please mark my answer as the accepted solution and give a thumbs up.

Best regards
Anders

Rising star 2024
MVP 2025
linkedIn: https://www.linkedin.com/in/andersskovbjerg/

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @spectura77 

 

https://www.servicenow.com/community/developer-forum/how-to-create-a-report-to-get-all-the-logged-in...

 

Seems not on sys user table.

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

spectura77
Tera Contributor

I have created a custom table and business rule for this but records are not being created in the custom table as expected when i login in and logout 

 

spectura77_0-1706272554684.png

this the script i am using in BR:

 

(function executeRule(current, previous /*null when async*/) {
    // Check if the event is a login event
    if (current.name == 'login' && current.param1) {
        // Extract user information from param1 field
        var userInformation = current.param1.toString();
       
        // Example: Splitting userInformation by a delimiter
        var userInfoArray = userInformation.split(',');
        if (userInfoArray.length > 1) {
            var userId = userInfoArray[1].trim();

            // Update login count in custom_login_log
            var loginLog = new GlideRecord('u_custom_login_log');
            loginLog.addQuery('user_id', userId);
            loginLog.query();
           
            if (loginLog.next()) {
                // Increment login count
                loginLog.u_login_count += 1;
                loginLog.update();
            } else {
                // Create a new record in custom_login_log
                var newLoginLog = new GlideRecord('u_custom_login_log');
                newLoginLog.initialize();
                newLoginLog.user_id = userId;
                newLoginLog.u_login_count = 1;
                newLoginLog.u_login_time = current.sys_created_on;
                newLoginLog.insert();
            }
        }
    }
})(current, previous);
 
Please guide