Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Client script to return user session time left

xiaix
Tera Guru

Is there any javascript that I can put into a Client Script to get the logged in user's session time?

I'm currently doing this in some UI Pages:

var _oneHourTimer = 0;

var tickerSeconds = 3600;

startOneHourTimer();

function oneHourTimerTicker()

{

      var el = document.getElementById('sessionReminder');

      if (el)

              el.innerHTML = ("Your session will expire in " + (--tickerSeconds) + " seconds.");

     

      if (tickerSeconds == 600) // 10 minute warning

              alert("Your ServiceNow session will expire in 10 minutes.   Be sure to SUBMIT any unsaved form data.");

     

      if (tickerSeconds == 300) // 5 minute warning

              alert("Your ServiceNow session will expire in 5 minutes.   Be sure to SUBMIT any unsaved form data.");

     

      if (tickerSeconds == 60) // 1 minute warning

              alert("Your ServiceNow session will expire in 1 minute.   Be sure to SUBMIT any unsaved form data.");

}

function startOneHourTimer()

{

      var el = document.getElementById('sessionReminder');

      if (el)

              el.innerHTML = ("Your session will expire in 1 hour (" + tickerSeconds + " seconds)");

     

      _oneHourTimer = setInterval(function(){ oneHourTimerTicker(); }, 1000);

}

This works fine, but instead of a hard-set guestimation of 3600, I'd like to pull the actual session time left before ServiceNow logs them out.

Any way to pull that data?

5 REPLIES 5

I would recommend using a new thread for this as then it's yours, you can attribute the correct answer and it will appear as not responded to.