OnSubmit setValue() doesn't work

Marina15
Tera Expert

Hello! why doesn't this script add people to the watchlist? When I press submit, the necessary people are added to the field, but they are no longer in the RITM

 

function onSubmit() {
    //Type appropriate comment here, and begin script below
    var watchList = g_form.getValue('watch_list');
    var group = new EfficientGlideRecord('sys_user_group');
    group.addField('manager');
    group.addField('u_add_admins');
    group.addQuery('u_sims_name', 'group');
    group.query(function(Egr) {
        if (Egr.next()) {
            if (watchList == '') {
                g_form.setValue('watch_list', group.getValue('manager') + ',' + group.getValue('u_add_admins'));
            } else {
                var newWatchList = watchList + ',' + group.getValue('manager') + ',' + group.getValue('u_add_admins');
                g_form.setValue('watch_list', newWatchList);
            }
        }
    });
}

 

  

1 REPLY 1

Brad Bowman
Kilo Patron
Kilo Patron

It looks like it's having trouble resolving one of the values when saving the form.  Try this approach instead:

var watchList = g_form.getValue('watch_list').split(',');
...
if (Egr.next()) {
    watchList.push(group.manager.toString());
    watchList.push(group.u_add_admins.toString());
    g_form.setValue('watch_list', watchList.join(','));
}
...

If it's still not working, try a test case where u_add_admins is blank so that you're only attempting to add a manager to the watchlist - try once when the watchlist starts empty, and once when it is not to be sure where the break-down is - then try a test case where the manager is blank but admins is not...