- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2023 11:56 PM
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2023 12:10 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2023 12:10 AM
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
