Having problems with your account or logging in?
A lot of changes are happening in the community right now. Some may affect you. READ MORE HERE
Highlighted
Paul Meaders Trusted Contributor.
Trusted Contributor.
685 views

Last login date/time for users

Jump to solution

Is there a way to find the last login date/time information for all of the defined users?  I need to create a usage report listing all users and the last time they accessed the application.

0 Likes
1 Solution

Accepted Solutions
Acclaimed Contributor.. Mark Cullen_1 Acclaimed Contributor..
Acclaimed Contributor..

Re: Last login date/time for users

Jump to solution

Below is logic to create a history record for each day user logged in regardless if login is multiple times a day.  This may not work for you if you truly want to know time of last login.  This logic is used in an environment where users cannot delete these history records since this history is associated to their employee record.

'****************************************************************************************************
'* Title          : Create employee history                                                         *
'*                                                                                                  *
'* Purpose        : This script will create a current day employee history for first time login.    *
'*                                                                                                  *
'* Called from    :                                                                                 *
'*    Workflows   :                                                                                 *
'*                                                                                                  *
'*    Wizards     :                                                                                 *
'*                                                                                                  *
'*    Scripts     : Action on Login                                                                 *
'*                                                                                                  *
'*    Buttons     :                                                                                 *
'*                                                                                                  *
'*    Libraries   :                                                                                 *
'*                                                                                                  *
'* Author         : Mark Cullen                                                                     *
'* Release Date   : 05/31/2012                                                                      *
'*                                                                                                  *
'* Author         :                                                                                 *
'* Modify Date    :                                                                                 *
'* Changes        :                                                                                 *
'*                                                                                                  *
'****************************************************************************************************

'====================================================================================================
'|                                      Variable Definitions                                        |
'|                                                                                                  |
'====================================================================================================

'--------------------------------------------- Variant ----------------------------------------------

'---------------------------------------------- Longs -----------------------------------------------
Dim lErr                      as Long
Dim lTrueFalse                as Long

'---------------------------------------------- Dates -----------------------------------------------

'--------------------------------------------- Strings ----------------------------------------------

'------------------------------------------ Record Handles ------------------------------------------
Dim hqRecord                  as Long
Dim hrRecord                  as Long

'====================================================================================================
'|                                    End Variable Definitions                                      |
'|                                                                                                  |
'====================================================================================================

Print "Create employee history - Started " & NOW()

lTrueFalse = 0

'Get current day history records
hqRecord = amQueryCreate()
lErr = amQueryGet(hqRecord,"SELECT lHistoryId,dtLastModif FROM amHistory WHERE lHistObjId = " & amLoginId() & " AND HistObjTable = 'amEmplDept' AND Field = 'LoginSlots' ORDER BY dtLastModif DESC")

'If current day history does not exist then create else ignore
IF lErr <> 0 THEN
   lTrueFalse = 1
ELSEIF DateValue(amGetFieldDateValue(hqRecord,1)) <> DateValue(NOW()) THEN
   lTrueFalse = 1
ELSE
   lTrueFalse = 0
END IF

IF lTrueFalse = 1 THEN
   Print Space(5) & "Creating login history record for lEmplDeptId = " & amLoginId()

   lErr = amStartTransaction()

   hrRecord = amCreateRecord("amHistory")
   lErr = amSetFieldstrValue(hrRecord,"Field","LoginSlots")
   lErr = amSetFieldStrValue(hrRecord,"HistObjTable","amEmplDept")
   lErr = amSetFieldLongValue(hrRecord,"lAuthorId",amLoginId())
   lErr = amSetFieldLongValue(hrRecord,"lHistObjId",amLoginId())
   lErr = amSetFieldStrValue(hrRecord,"PreviousVal","Creation")
   lErr = amInsertRecord(hrRecord)
   lErr = amReleaseHandle(hrRecord)

   lErr = amCommit()
ELSE
   Print Space(5) & "No history created"
END IF

lErr = amReleaseHandle(hqRecord)

Print "Create employee history - Finished " & NOW()

RetVal = 0   
Exit function

7 Replies
Acclaimed Contributor.. Mark Cullen_1 Acclaimed Contributor..
Acclaimed Contributor..

Re: Last login date/time for users

Jump to solution

There is nothing out of the box for this so customization is needed.

0 Likes
poojam Super Contributor.
Super Contributor.

Re: Last login date/time for users

Jump to solution

Hello Mark,

What kind of customization is needed??

Could you please give any hint/suggestion??

0 Likes
Acclaimed Contributor.. Mark Cullen_1 Acclaimed Contributor..
Acclaimed Contributor..

Re: Last login date/time for users

Jump to solution

Create an action script and associate to the 'Action on login' element found under Profile tab of amEmplDept.  Every time a user logs in this action will execute.  Depending on how you want to report, the action script can populate a datetime element (ie. new field on amEmplDept) or create a history record against their employee record (make sure they cannot delete) or create a separate table to store pertinent information.

0 Likes
Acclaimed Contributor.. Mark Cullen_1 Acclaimed Contributor..
Acclaimed Contributor..

Re: Last login date/time for users

Jump to solution

Below is logic to create a history record for each day user logged in regardless if login is multiple times a day.  This may not work for you if you truly want to know time of last login.  This logic is used in an environment where users cannot delete these history records since this history is associated to their employee record.

'****************************************************************************************************
'* Title          : Create employee history                                                         *
'*                                                                                                  *
'* Purpose        : This script will create a current day employee history for first time login.    *
'*                                                                                                  *
'* Called from    :                                                                                 *
'*    Workflows   :                                                                                 *
'*                                                                                                  *
'*    Wizards     :                                                                                 *
'*                                                                                                  *
'*    Scripts     : Action on Login                                                                 *
'*                                                                                                  *
'*    Buttons     :                                                                                 *
'*                                                                                                  *
'*    Libraries   :                                                                                 *
'*                                                                                                  *
'* Author         : Mark Cullen                                                                     *
'* Release Date   : 05/31/2012                                                                      *
'*                                                                                                  *
'* Author         :                                                                                 *
'* Modify Date    :                                                                                 *
'* Changes        :                                                                                 *
'*                                                                                                  *
'****************************************************************************************************

'====================================================================================================
'|                                      Variable Definitions                                        |
'|                                                                                                  |
'====================================================================================================

'--------------------------------------------- Variant ----------------------------------------------

'---------------------------------------------- Longs -----------------------------------------------
Dim lErr                      as Long
Dim lTrueFalse                as Long

'---------------------------------------------- Dates -----------------------------------------------

'--------------------------------------------- Strings ----------------------------------------------

'------------------------------------------ Record Handles ------------------------------------------
Dim hqRecord                  as Long
Dim hrRecord                  as Long

'====================================================================================================
'|                                    End Variable Definitions                                      |
'|                                                                                                  |
'====================================================================================================

Print "Create employee history - Started " & NOW()

lTrueFalse = 0

'Get current day history records
hqRecord = amQueryCreate()
lErr = amQueryGet(hqRecord,"SELECT lHistoryId,dtLastModif FROM amHistory WHERE lHistObjId = " & amLoginId() & " AND HistObjTable = 'amEmplDept' AND Field = 'LoginSlots' ORDER BY dtLastModif DESC")

'If current day history does not exist then create else ignore
IF lErr <> 0 THEN
   lTrueFalse = 1
ELSEIF DateValue(amGetFieldDateValue(hqRecord,1)) <> DateValue(NOW()) THEN
   lTrueFalse = 1
ELSE
   lTrueFalse = 0
END IF

IF lTrueFalse = 1 THEN
   Print Space(5) & "Creating login history record for lEmplDeptId = " & amLoginId()

   lErr = amStartTransaction()

   hrRecord = amCreateRecord("amHistory")
   lErr = amSetFieldstrValue(hrRecord,"Field","LoginSlots")
   lErr = amSetFieldStrValue(hrRecord,"HistObjTable","amEmplDept")
   lErr = amSetFieldLongValue(hrRecord,"lAuthorId",amLoginId())
   lErr = amSetFieldLongValue(hrRecord,"lHistObjId",amLoginId())
   lErr = amSetFieldStrValue(hrRecord,"PreviousVal","Creation")
   lErr = amInsertRecord(hrRecord)
   lErr = amReleaseHandle(hrRecord)

   lErr = amCommit()
ELSE
   Print Space(5) & "No history created"
END IF

lErr = amReleaseHandle(hqRecord)

Print "Create employee history - Finished " & NOW()

RetVal = 0   
Exit function

poojam Super Contributor.
Super Contributor.

Re: Last login date/time for users

Jump to solution

Hello Mark!

Thanks for the solution you have provided. I will surely try this in my environment and will post you the result here!!

Regards,

Pooja

0 Likes
GoldenRatioRJP Honored Contributor.
Honored Contributor.

Re: Last login date/time for users

Jump to solution

If you just want to know the last time a User logged in a lighter weight way can just be to add a dat field to the amEmplDept table.  Then do just as Mark suggests and have it updated as part of the "Action On Login".  Heck, if you do want to track back more than just the most recent connection just turn History on for the new field.  Several different ways to something similar to what you want.  The specifics will depend of your actual functional requirement.

Cheers,

Russ

Russell Parker, CITAM, CHAMP, CSAM
President - Golden Ratio, Inc.
Russ.Parker@GoldenRatioInc.com
0 Likes
poojam Super Contributor.
Super Contributor.

Re: Last login date/time for users

Jump to solution

Hello Expert,

I had achieved this by writting trigger in SQL server database level.

Below steps you need to performed to achieved the same,

1. Create new table (amDupliLoginSlot) same as 'amLoginSlot'.

which has below values,

lDupliLoginSlotID (primary key ) -int
dupllKey
dupAppliName,
dupseLoginClass,
duplLoginId,
LogonDate
LogoffDate
ldlLoginUserId (link between amDupliLoginSlot and amLoginSlot)

2. Now simply to need to create SQL-Squence as amDupliLoginSlot_seq in sql

syntax: 

CREATE SEQUENCE Test.CountBy1

START WITH 1

INCREMENT BY 1 ;

GO  

3. Finally you need to write two triggers on 'amLoginSlot' , 1. on Insert 2. on Delete

Insert trigger is create entry in dupli table once user login to AM application. and delete trigger will work once user logoff from AM application and update the entry of Logoff date in duplicate table.

Thanks,

Pooja Manjarekar

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.