Script need to wait for time ordered by customer

Nagavardhini
Tera Contributor

Hi all,
User should be given access for specified durations (2 hours,4 hours and 6 hours)depending on the number he enters on the portal. Script need to wait for time ordered by customer.
can anyone help with script

1 ACCEPTED SOLUTION

Anand Kumar P
Tera Patron

Hi @Nagavardhini  ,

You have to write the schedule job and get the value entered by user and 

var now = new GlideDateTime();
var durationThreshold = 2;//get the value from user submitted through protal from reqest item varibles or custom reocrd
var sessionGr = new GlideRecord('v_user_session_list');
sessionGr.addQuery('last_accessed', '<', now.subtract(durationThreshold * 60 * 60 * 1000));
sessionGr.addQuery('transaction_duration', '=', durationThreshold);
sessionGr.query();
while (sessionGr.next()) {
    var userId = sessionGr.user;
    var userGr = new GlideRecord('sys_user');
    if (userGr.get(userId)) {
        userGr.locked_out = true;
        userGr.update();
        gs.info('User ' + userId + ' locked out due to session conditions.');
    }
}

Mark it as helpful and solution proposed if it serves your purpose.

Thanks,

Anand

View solution in original post

1 REPLY 1

Anand Kumar P
Tera Patron

Hi @Nagavardhini  ,

You have to write the schedule job and get the value entered by user and 

var now = new GlideDateTime();
var durationThreshold = 2;//get the value from user submitted through protal from reqest item varibles or custom reocrd
var sessionGr = new GlideRecord('v_user_session_list');
sessionGr.addQuery('last_accessed', '<', now.subtract(durationThreshold * 60 * 60 * 1000));
sessionGr.addQuery('transaction_duration', '=', durationThreshold);
sessionGr.query();
while (sessionGr.next()) {
    var userId = sessionGr.user;
    var userGr = new GlideRecord('sys_user');
    if (userGr.get(userId)) {
        userGr.locked_out = true;
        userGr.update();
        gs.info('User ' + userId + ' locked out due to session conditions.');
    }
}

Mark it as helpful and solution proposed if it serves your purpose.

Thanks,

Anand