Getting UI Page List Collector value

Ethan Davies
Mega Sage
Mega Sage

Hi there, 

I am trying to get the values from a List Collector that I have coded on a UI Page so that I can set these values into a List Collector variable that I have created on the Change Request form. However, whenever I try to get the value of the documentElement of the List Collector from the UI Page, then the value returned is a value of 'null'. The code snippets are below. Wondering if anyone can help me with this, or give me any pointers.

Thanks in advance!

 

UI Page

<?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:ui_form>
  <!-- Get values from dialog preferences passed in -->
  <g:evaluate var="jvar_short_text"
    expression="RP.getWindowProperties().get('short_text')" />
  <g:evaluate var="jvar_comments_text"
    expression="RP.getWindowProperties().get('comments_text')" />
   <!-- Set up form fields and labels -->
   <table width="100%">
     <tr id="description_row" valign="top">
        <td colspan="1">
           <!-- Short description value used as a label -->
           ${jvar_short_text}
        </td>
     </tr>
     <tr>
       <td>
         <!-- Comments text field (Contains comments from originating record as a default) -->
		  <g:macro_invoke macro= "lightweight_glide_list" id="userList" name="userList" control_name="listCollector" reference="sys_user" can_write="true" />
       </td>
     </tr>
     <tr>
       <td colspan="2">
       </td>
     </tr>
     <tr id="dialog_buttons">
        <td colspan="2" align="right">
           <!-- Pull in 'dialog_buttons_ok_cancel' UI Macro for submit/cancel buttons.'ok' option will call the 'validateComments' Client script function from the UI Page-->
           <g:dialog_buttons_ok_cancel ok="return validateSelection()" ok_type="button" cancel_type="button" />
        </td>
     </tr>
  </table>
</g:ui_form>
</j:jelly>

Client Script

function validateSelection() {
	try {
		//Gets called if the 'OK' dialog button is clicked
		//Make sure dialog comments are not empty
		
		var users = gel("userList").value;
		//If comments are not empty do this...
		GlideDialogWindow.get().destroy(); //Close the dialog window
		g_form.setValue('u_additional_approvers_defined', true); // Set the 'Additional Approvers Defined' boolean flag to true
		g_form.setValue("u_additional_approvers", users); //Set the users selected in the list collector to the list on the Change Request.
	} catch (err) {
		g_form.addErrorMessage(err);
	}
	
	
}
1 ACCEPTED SOLUTION
5 REPLIES 5

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Ethan,

That won't work. Since the html code for the list collector is inside the Macro since you are calling the UI macro

Is this for catalog item? they why not use slush bucket variable?

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

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

Hi Ankur, 

 

Thanks for your reply! No this is for the Change Request form, where I have some functionality to add additional approvers other than those defined in the Change Approval Policies. I have tried it using a reference field instead of a list collector and it works correctly. I will try using the slush bucket idea which is a good one and mark the answer as correct If I have any success!

 

Thanks, 

Ethan

Thanks Jay! Will give this approach a go 🙂