# Timer Clock Perspective

**URL:** <https://forum.inductiveautomation.com/t/timer-clock-perspective/84843>\
**Category:** Ignition\
**Tags:** perspective, scripting\
**Created:** [January 27, 2024, 12:17pm UTC](https://forum.inductiveautomation.com/t/timer-clock-perspective/84843 "2024-01-27T12:17:08Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vatsal\_Shah](https://avatars.discourse-cdn.com/v4/letter/v/0ea827/32.png) [@Vatsal\_Shah](https://forum.inductiveautomation.com/u/Vatsal_Shah)\
**Post date:** [January 27, 2024, 12:17pm UTC](https://forum.inductiveautomation.com/t/timer-clock-perspective/84843/1 "2024-01-27T12:17:08Z")

</div>

I want to display a countdown timer on one of my perspective view.  
For eg. as soon as a user logs-in I want to display a countdown timer for 1hr. Is there any way I can achieve this ?

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [January 27, 2024, 12:53pm UTC](https://forum.inductiveautomation.com/t/timer-clock-perspective/84843/2 "2024-01-27T12:53:00Z")

</div>

- Create a session custom property, `countdownStart`.
- When the user logs in run the following code in a script:

```auto
	self.session.custom.countdownStart = system.date.now()

```

- On your countdown label create an expression binding to calculate the time remaining. For example,  
`floor((now(1000) - {session.custom.countdownStart}) /1000)`  
will tell you the number of seconds since countdownStart.
- Modify the expression to give the number of seconds remaining.
- Modify the expression to clamp the time remaining at zero (to prevent it going negative).
- Modify the expression to give the time remaining in mm:ss format.

---

<div class="post-metadata">

**Author:** ![Vatsal\_Shah](https://avatars.discourse-cdn.com/v4/letter/v/0ea827/32.png) [@Vatsal\_Shah](https://forum.inductiveautomation.com/u/Vatsal_Shah)\
**Post date:** [January 27, 2024, 1:01pm UTC](https://forum.inductiveautomation.com/t/timer-clock-perspective/84843/3 "2024-01-27T13:01:37Z")

</div>

where to write this script ?: self.session.custom.countdownStart = system.date.now()

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [January 27, 2024, 1:02pm UTC](https://forum.inductiveautomation.com/t/timer-clock-perspective/84843/4 "2024-01-27T13:02:59Z")

</div>

In your login script. You haven't explained how you're doing this.

---

<div class="post-metadata">

**Author:** ![Vatsal\_Shah](https://avatars.discourse-cdn.com/v4/letter/v/0ea827/32.png) [@Vatsal\_Shah](https://forum.inductiveautomation.com/u/Vatsal_Shah)\
**Post date:** [January 27, 2024, 1:06pm UTC](https://forum.inductiveautomation.com/t/timer-clock-perspective/84843/5 "2024-01-27T13:06:21Z")

</div>

I just want thing like whenever a user login(opens a session in browser) the timer countdown timer should start.

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [January 27, 2024, 1:07pm UTC](https://forum.inductiveautomation.com/t/timer-clock-perspective/84843/6 "2024-01-27T13:07:15Z")

</div>

That's what you wrote in your opening post. It doesn't add any new information.

---

<div class="post-metadata">

**Author:** ![Vatsal\_Shah](https://avatars.discourse-cdn.com/v4/letter/v/0ea827/32.png) [@Vatsal\_Shah](https://forum.inductiveautomation.com/u/Vatsal_Shah)\
**Post date:** [January 27, 2024, 1:08pm UTC](https://forum.inductiveautomation.com/t/timer-clock-perspective/84843/7 "2024-01-27T13:08:58Z")

</div>

I'm logging in with IDP.  
Need guidance how to proceed with the timer thing

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [January 27, 2024, 1:10pm UTC](https://forum.inductiveautomation.com/t/timer-clock-perspective/84843/8 "2024-01-27T13:10:37Z")

</div>

**How** are you logging in? Button event? Script? Application launch? You need to be **much** more specific in the details you supply.

---

<div class="post-metadata">

**Author:** ![Vatsal\_Shah](https://avatars.discourse-cdn.com/v4/letter/v/0ea827/32.png) [@Vatsal\_Shah](https://forum.inductiveautomation.com/u/Vatsal_Shah)\
**Post date:** [January 27, 2024, 1:14pm UTC](https://forum.inductiveautomation.com/t/timer-clock-perspective/84843/9 "2024-01-27T13:14:51Z")

</div>

I'm launching the project from the designer.  
It then opens in browser as usual there it asks for user id and pw (initially I told doing it with idp but for now keeping that aside).  
After this it launches my project

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [January 27, 2024, 1:25pm UTC](https://forum.inductiveautomation.com/t/timer-clock-perspective/84843/10 "2024-01-27T13:25:37Z")

</div>

That's better.  
Add the code into Project Browser → Perspective → Session Events → Page Startup.

You might also go back through some of your other threads and see if any of the problems were answered to your satisfaction. As far as I can see you haven't marked any of the answers as 'Solution'.

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [January 28, 2024, 6:30pm UTC](https://forum.inductiveautomation.com/t/timer-clock-perspective/84843/11 "2024-01-28T18:30:12Z")

</div>

> [@Transistor](#):
>
> Project Browser → Perspective → Session Events → Page Startup

Not sure about this. I would be putting a value change event handler on the session.props.auth.user.userName to set the custom session prop

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [January 28, 2024, 6:31pm UTC](https://forum.inductiveautomation.com/t/timer-clock-perspective/84843/12 "2024-01-28T18:31:18Z")

</div>

Good idea. Can you post a step-by-step?

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [January 28, 2024, 6:32pm UTC](https://forum.inductiveautomation.com/t/timer-clock-perspective/84843/13 "2024-01-28T18:32:01Z")

</div>

Can do when I'm in the office in a few hours

---

<div class="post-metadata">

**Author:** ![Vatsal\_Shah](https://avatars.discourse-cdn.com/v4/letter/v/0ea827/32.png) [@Vatsal\_Shah](https://forum.inductiveautomation.com/u/Vatsal_Shah)\
**Post date:** [January 29, 2024, 5:58am UTC](https://forum.inductiveautomation.com/t/timer-clock-perspective/84843/14 "2024-01-29T05:58:45Z")

</div>

I was wondering, will "putting a value change event handler on the session.props.auth.user.userName to set the custom session prop" will work if the same user logs in again?

Asking this because i'm building something like : every one hour the user need to log in again.

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [January 29, 2024, 6:03am UTC](https://forum.inductiveautomation.com/t/timer-clock-perspective/84843/15 "2024-01-29T06:03:09Z")

</div>

It will run whenever the userName changes

---

<div class="post-metadata">

**Author:** ![Vatsal\_Shah](https://avatars.discourse-cdn.com/v4/letter/v/0ea827/32.png) [@Vatsal\_Shah](https://forum.inductiveautomation.com/u/Vatsal_Shah)\
**Post date:** [January 29, 2024, 6:07am UTC](https://forum.inductiveautomation.com/t/timer-clock-perspective/84843/16 "2024-01-29T06:07:29Z")

</div>

Can you post a step-by-step solution pls.

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [January 29, 2024, 6:18am UTC](https://forum.inductiveautomation.com/t/timer-clock-perspective/84843/17 "2024-01-29T06:18:32Z")

</div>

Something like this:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/2/b/2beb9904d3175f960d97e14e7edf35db7571d82f.png)

The logout doesn't work atm as I think you need to pass in the session id... but I always forget how to do this
