workflow user activity check code
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2024 06:38 AM
Hi all i have written this code in user activity if requester is inactive user so on the basis of inactive user i am running this code but only else part run that user is not found where i am doing mistake
var answer = []; var requested = current.variables.requested_name.getDisplayValue(); gs.info("Requester name is: " + requested); var grRequester = new GlideRecord('sys_user'); grRequester.addQuery('user_name', requested); grRequester.query(); if (grRequester.next()) { if (!grRequester.active) { var grActive = new GlideRecord('sys_user'); grActive.addQuery('active', true); grActive.query(); if (grActive.next()) { answer.push(grActive.sys_id); gs.info("The active approver is: " + grActive.sys_id); } else { gs.error("No active users found for approver."); } } else { gs.info("Requested user is active, no approver needed."); } } else { gs.error("Requested user not found."); }
Note after requesting item and select requester user no approver generate in logs this message come
this message populate in logs user not found
where i am doing mistake
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2024 06:41 AM
Hi,
Just a tip, Please use the code editor to include scripts to make it more readable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2024 06:43 AM
var answer = [];
var requestedUser = current.variables.requested_name.getDisplayValue();
gs.info("Requested User: " + requestedUser);
var grRequestedUser = new GlideRecord('sys_user');
grRequestedUser.addQuery('user_name', requestedUser);
grRequestedUser.query();
if (grRequestedUser.next()) {
gs.info("Requested user found: " + grRequestedUser.user_name);
if (!grRequestedUser.active) {
var grActive = new GlideRecord('sys_user');
grActive.addQuery('active', true);
grActive.query();
// Check if an active user is found
if (grActive.next()) {
// Add the sys_id of the active user to the answer array
answer.push(grActive.sys_id);
gs.info("Active user found for inactive requester: " + requestedUser);
gs.info("Approver added: " + grActive.sys_id);
} else {
gs.error("No active users found for approver.");
}
} else if (grRequestedUser.active) {
gs.info("Requested user is active, no approver needed.");
}
} else {
gs.error("Requested user not found.");
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2024 06:49 AM
var answer = [];
var requestedUser = current.variables.requested_name.getDisplayValue();
gs.info("Requested User: " + requestedUser);
var grRequestedUser = new GlideRecord('sys_user');
grRequestedUser.addQuery('user_name', requestedUser);
grRequestedUser.query();
if (grRequestedUser.next()) {
gs.info("Requested user found: " + grRequestedUser.user_name);
if (!grRequestedUser.active) {
var grActive = new GlideRecord('sys_user');
grActive.addQuery('active', true);
grActive.query();
// Check if an active user is found
if (grActive.next()) {
// Add the sys_id of the active user to the answer array
answer.push(grActive.sys_id);
gs.info("Active user found for inactive requester: " + requestedUser);
gs.info("Approver added: " + grActive.sys_id);
} else {
gs.error("No active users found for approver.");
}
} else if (grRequestedUser.active) {
gs.info("Requested user is active, no approver needed.");
}
} else {
gs.error("Requested user not found.");
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2024 06:45 AM - edited 03-13-2024 06:46 AM
See my comment below, also show what logs/ info messages you are getting
var answer = [];
var requested = current.variables.requested_name.getDisplayValue();
gs.info("Requester name is: " + requested);
var grRequester = new GlideRecord('sys_user');
grRequester.addQuery('user_name', requested);
grRequester.query();
if (grRequester.next()) {
if (!grRequester.active) {
var grActive = new GlideRecord('sys_user'); //whata re you trying to do here? this will randomly pick a user which is active, this should have another query to filter right users
grActive.addQuery('active', true);
grActive.query();
if (grActive.next()) {
answer.push(grActive.sys_id);
gs.info("The active approver is: " + grActive.sys_id);
}
else {
gs.error("No active users found for approver.");
}
}
else {
gs.info("Requested user is active, no approver needed.");
}
}
else {
gs.error("Requested user not found.");
}