create a background script to enable notification on the sys_users

Ricardo Sanche3
Tera Contributor

how can I enable the notification field for all users, in the sys_users? I have over 7000 users and I don't want to do it one by one, currently, it is set to disable.

Emails.JPG

1 ACCEPTED SOLUTION

Bert_c1
Kilo Patron

Hi,

Try the following:

 

// Enable notification for users where it is disabled
var dryRun = true;
var suRecord = new GlideRecord('sys_user');
suRecord.addEncodedQuery('notification=1');
suRecord.query();
gs.info("EnableUserNotification: Updating " + suRecord.getRowCount() + " records.");
while (suRecord.next()) {
    gs.info("EnableUserNotification: Updating user: " + suRecord.name);
    suRecord.notification = 2;
    if (!dryRun) 
        suRecord.update();
}

 

set 'dryRun' to false after testing.

View solution in original post

1 REPLY 1

Bert_c1
Kilo Patron

Hi,

Try the following:

 

// Enable notification for users where it is disabled
var dryRun = true;
var suRecord = new GlideRecord('sys_user');
suRecord.addEncodedQuery('notification=1');
suRecord.query();
gs.info("EnableUserNotification: Updating " + suRecord.getRowCount() + " records.");
while (suRecord.next()) {
    gs.info("EnableUserNotification: Updating user: " + suRecord.name);
    suRecord.notification = 2;
    if (!dryRun) 
        suRecord.update();
}

 

set 'dryRun' to false after testing.