Function setValue() to set multiple values on a field.

H_ctor Blanco
Kilo Guru

Hi all,

I`m trying to implement a client script to fill in the into the watchlist field "u_rta" using the setValue() function. I can do it with one user but I don“t know how to fill the field with another 2 fields.

I need something like: g_form.setValue('Watch_List', user1,user2,user3);

I have implemented the following code:

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    //Type appropriate comment here, and begin script below
    g_form.setValue('Watch_List_email', "");
    g_form.setValue('Watch_List', "");

    if (newValue == '5ebd8536db94c4949f43ff361d9619a7') { 
        var grCCS = new GlideRecord('cmdb_ci_service');
        if (grCCS.get('5ebd8536db94c4949f43ff361d9619a7')) {
            g_form.setValue('Watch_List', grCCS.u_rta);
        }
    }
}

 

1 ACCEPTED SOLUTION

H_ctor Blanco
Kilo Guru

Finally solved my issue with the following syntax:

g_form.setValue('Watch_List', app.u_gta + ',' + app.managed_by + ',' + app.u_rsa_backup);

View solution in original post

9 REPLIES 9

Alok Gupta5
Tera Guru
Tera Guru

Hello,

You can not set multiple values in watch list.

 

Regards,

Alok Gupta

Yousaf
Giga Sage

Hi Hector,

Try setMultipleValues().

Mark Correct or Helpful if it helps.

Thanks,

Yousaf


***Mark Correct or Helpful if it helps.***

Hitoshi Ozawa
Giga Sage
Giga Sage

Hi,

Just pass comma delimited sys_id of users.

e.g.

g_form.setValue('watch_list', '62826bf03710200044e0bfc8bcbe5df1,a8f98bb0eb32010045e1a5115206fe3a');

find_real_file.png

Hi again,

Something like below.

    var ciArray = [];
    var grCCS = new GlideRecord('cmdb_ci_service');
    grCCS.addQuery('name', 'IN', 'SAP Payroll,SAP Labor Distribution');  // change select criteria to fit need
    grCCS.query();
    while (grCCS.next()) {
        ciArray.push(grCCS.sys_id.toString());
    }
    g_form.setValue('watch_list', ciArray.join(','));  // JavaScript is case sensitive. OOTB field name is "watch_list" with all lowercase letters.