Skip to main content
Best answer by pshashipreetham

Hi @slangley 

 

Thanks for the Follow-up, and Thanks, @nmutter @TanmeyTWX @VladimirRosu_116627, for all the replies. We have written the custom logic to record the User Active Status when a user opens the Landing Page.


Also, I have submitted the Idea:
A Option to Record the User last Active - PTC Community

Thanks,

2 replies

24-Ruby III
August 31, 2023

Take a look this discussion - "Capture User Account Lockout Event": https://community.ptc.com/t5/ThingWorx-Developers/Capture-User-Account-Lockout-Event/td-p/642575

pshashipreetham
18-Opal
18-Opal
September 3, 2023

Hi @VladimirN ,

 

This is not what we are looking for, and we need the timestamp when the User last logged In.

 

Thanks,

24-Ruby III
September 4, 2023

Try this example:

 

"1. Retrieve User Login Info: You can use the UserEntity service `GetLoginHistory` to get the login history for a user. This service returns a result set that contains information about user logins.

2. Filter Login History: Once you have the login history, you can filter it to get the last logged-in timestamp. The login history returned by `GetLoginHistory` is ordered by timestamp, so you can simply retrieve the first entry.

Here's an example of how you can achieve this using the ThingWorx REST API:

```
GET /Thingworx/Things/UserEntity/Services/GetLoginHistory?name=<username>&appKey=<your_app_key>
```
Replace `<username>` with the username of the user you want to retrieve the login history for, and `<your_app_key>` with your ThingWorx application key.

This API call will return a JSON response containing the login history for the user. You can parse the response to extract the timestamp of the last login".

19-Tanzanite
September 4, 2023

I am not sure if this works in the case you use the SSO authenticator, but each User has a property called "lastConnection", that you would see if you create a service where you reference any User administrator, in its available properties.

In my non-SSO environment, this works correctly:

result = Users["Administrator"].lastConnection;

pshashipreetham
18-Opal
18-Opal
September 4, 2023

Hi @VladimirRosu_116627,

 

Thanks for sharing the input. Based on it, what I found is:

  1. For Non-SSO Users: Users["Administrator"].lastConnection;
  2. For SSO Users: Users["Administrator"].GetLastModifiedDate();

But both ways, the Timestamp will reset when the Server is restarted.

 

Thanks,

17-Peridot
September 4, 2023

Hi Shashi,

 

To achieve your requirement, you need to develop your own logic on top of what @VladimirRosu_116627 mentioned above. I had developed the exact User usage report for every user login. You could trigger a service on master load on every user login which will do an entry to a stream so that you can get all the historic login attempts and then prepare the report.