- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2021 01:36 AM
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.
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);
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2021 04:51 AM
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);
}
Output:
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2021 06:06 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2021 06:22 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2021 09:17 AM
Hi Ankur,
Thank you very much for the explanation.
Best regards,
Pethum De Silva
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-29-2023 05:19 AM
How to add filter for list collector
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2023 05:41 AM
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