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

Hello Ankur,

 

Thanks for the correct answer, It's working fine.

I have a question regarding your solution since we accessing browser dom directly. Is it the best way to do this?

 

Best regards,

Pethum De Silva 

Hi,

that is usually the way we use to determine the HTML id and then have our script work as per the case.

Also in most of the UI page scripts we do use DOM

Regards
Ankur

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

Hi Ankur,

 

Thank you very much for the explanation.

 

Best regards,

Pethum De Silva

How to add filter for list collector

 

Girish Nagaraj
Tera Contributor

Hi @Ankur Bawiskar ,

 

I have tried the same, But i was not able to achieve. My requirement was to pass the glide_list field value from incident to UI Page and from UI page to Incident on click of button. Request you to help me on this.

 

Regards,
Girish