The CreatorCon Call for Content is officially open! Get started here.

Get list collector values in UI page in ServiceNow platform

pethumdesilva
Tera Guru

Hi,

I have a requirement to get the user preference using dialog box in ServiceNow  Change request.  In dialog box, it will display the list of users in a list collector as below.find_real_file.png

I used following steps,

1.Create a new UI page and it will use the macro to show the list collector as follows,

HTML

 <div class="col-md-8">
<g:evaluate var="jvar_assignee" expression="RP.getWindowProperties().get('assignee_list')"/>
<g:macro_invoke macro= "lightweight_glide_list" id="change_subsystem" name="change_subsystem" control_name="QUERY:companyLIKEASP" reference="sys_user" can_write="true" list_data ="${jvar_assignee}" />
</div>

 

2 Create ui action and it will open the dialog box and pass the assignee_list, 

var assignList = g_form.getValue("additional_assignee_list");
var dialog = new GlideDialogWindow("user_input"); 
dialog.setPreference("assignee_list", assignList);
dialog.render();
dialog.setTitle('Calendar Invite');

When the user click the OK button, I want to read the selected user list from list collector, but value is always null.

I tried following script to read the data from list collector, but those are not working.

1. var selectedList = gel('change_subsystem').value;

2. var selectedList =  g_list.get(change_subsystem);

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

I was able to get the sys_ids of the users from that list collector on UI page

Script:

HTML:

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">

	<g:macro_invoke id="user" name="user" macro= "lightweight_glide_list" control_name="user" reference="sys_user" can_write="true"/>

	<g:dialog_buttons_ok_cancel cancel="return onCancel();" ok="return onSubmit();"/>

</j:jelly>

Client Script: Notice the HTML ID -> for me it was select_0user

function onSubmit(){

    var x = document.getElementById("select_0user");
    var txt = "Selected users: ";
    var i;
    for (i = 0; i < x.length; i++) {
        txt = txt + "\n" + x.options[i].value;
    }
    alert(txt);

}

find_real_file.png

Output:

find_real_file.png

Regards
Ankur

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

View solution in original post

9 REPLIES 9

BALAJI40
Mega Sage

Hi,

Have you tries with below syntax,

var selectedList = gel('jvar_assignee').value; or g_form.getValue('change_subsystem');

 

Hi Balaji,

 

Thanks for the reply, I tried your solution but it's not working..

 

BR

 

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

did you check the html id for that HTML element

Regards
Ankur

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

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

I was able to get the sys_ids of the users from that list collector on UI page

Script:

HTML:

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">

	<g:macro_invoke id="user" name="user" macro= "lightweight_glide_list" control_name="user" reference="sys_user" can_write="true"/>

	<g:dialog_buttons_ok_cancel cancel="return onCancel();" ok="return onSubmit();"/>

</j:jelly>

Client Script: Notice the HTML ID -> for me it was select_0user

function onSubmit(){

    var x = document.getElementById("select_0user");
    var txt = "Selected users: ";
    var i;
    for (i = 0; i < x.length; i++) {
        txt = txt + "\n" + x.options[i].value;
    }
    alert(txt);

}

find_real_file.png

Output:

find_real_file.png

Regards
Ankur

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