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

Hi Hitoshi,

I just tried this:

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

grCCS.u_gta contains the sys_id.

It doesn´t work for me:

 

Hi,

Need to remove the single quote.

Does sys_id of each of grCCS.u_gta, grCCS.managed_by, and u_rsa_backup contain a sys_id? If so, try the following.

Is the watch list variable name "Watch_List" with upper case "W" and "L"? OOTB, it's "watch_list" with all lowercase.

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

Finally, check the post after posting a reply to see if the content is correctly displayed. It is necessary to save an image to local pc and then attach it to the post.

Hi,

The variable name "Watch_List" is correct.

I have tested your code but still not working.

As you can see on the next image, grCCS.u_gta contains the sys_id of the user. 

find_real_file.png

If I add only one user, it works.

g_form.setValue('Watch_List', grCCS.u_gta);

find_real_file.png

Sorry for the issues with the images on the previous response.

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

As mentioned by Hitoshi you need to set comma separated sysIds and it would work

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

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);