- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-15-2024 12:46 AM
Hi Community,
I have requirement where i have to check if list type field contains all inactive users
please correct my below code
in this code i'm getting any one is inactive user but i want all inactive then show msg
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-15-2024 01:31 AM
Try below code:
var listField = current.list_field.toString();
count = 0;
for (i=0;i<=listField.lenght;i++) {
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id', listField[i]);
gr.addQuery('active', true);
gr.query();
if (gr.next()) {
count++;
}
}
if (count == 0)
gs.addErrorMessage("All users are inactive");
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-15-2024 01:06 AM
Hi @shweta14,
No need to iterate through the whole list, try something like below:
var gr = new GlideRecord('sys_user');
gr.addQuery("sys_id", "IN", listfieldValue);
gr.addQuery('active', true);
gr.query();
if(gr.getRowCount()== 0)
{
gs.print("All users are inactive");
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-15-2024 01:07 AM
Hi Shwetha,
Try this, since list collector return sysIds, I have used sysIds in the query part
var r = new GlideAggregate('sys_user');
r.addQuery('sys_id', 'IN', 'a8f98bb0eb32010045e1a5115206fe3a,71826bf03710200044e0bfc8bcbe5d3b,12826bf03710200044e0bfc8bcbe5db1');
r.addAggregate('COUNT', 'active');
r.query();
while(r.next()){
gs.print(r.active + ' ' + r.getAggregate('COUNT', 'active'));
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-15-2024 01:11 AM
Hi @shweta14 to look multiple users you need to use while condition instead of if
if (gr.next()) { // replace to while
here is sample code
Harish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-15-2024 01:31 AM
Try below code:
var listField = current.list_field.toString();
count = 0;
for (i=0;i<=listField.lenght;i++) {
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id', listField[i]);
gr.addQuery('active', true);
gr.query();
if (gr.next()) {
count++;
}
}
if (count == 0)
gs.addErrorMessage("All users are inactive");