Trouble Displaying Array on UI Page

Matthew Glenn
Kilo Sage

On a UI Page, I'm running two Glide queries (against sys_user and a custom table) and storing the results into an array. After that, I'm taking the two arrays, finding the difference between the two using ArrayUtil()   and then trying to display the difference out on a UI Page. That's where I'm running into an issue. When I display the results I want (the difference), I simply get 'null' for each returned value. One thing to note is, the custom_table.u_name field referenced in the code below is a reference to sys_user.

<g:evaluate var="jvar_resultsarray">

      var donearray = [];

      done = new GlideRecord('custom_table');

      done.query();

      while(done.next()){

              donearray.push(done.u_name.toString());

      }

      donearray;

      var outstandingarray = [];

      var notdone = new GlideRecord('sys_user');

      var queryNotDone = 'department=674a86516ffe9900ef9c164e5d3ee4b1^active=true';

      notdone.addEncodedQuery(queryNotDone);

      notdone.query();

      while(notdone.next()){

              outstandingarray.push(notdone.middle_name.toString());

      }

      outstandingarray;

      diffArray = new ArrayUtil().diff(outstandingarray,donearray);

      diffArray;

</g:evaluate>

<!--display array-->

div>

      <j:forEach var ="jvar_array" items="${diffArray}" indexVar="jvar_i">

      <g:evaluate var="jvar_s" expression="jvar_array[${jvar_i}]" />

              ${jvar_s}<br/>

      </j:forEach>

</div>

From what I can tell, the above works (definitely works in a background script when you strip the glide/jelly tags). But again, displaying it out on a UI Page results in a bunch of nulls. I built what I have using suggestions from How to retrieve element from array in a jelly tag, but can't seem to get any further on my own.

1 ACCEPTED SOLUTION

Brad Tilton
ServiceNow Employee
ServiceNow Employee

Have you tried the following for lines 29-32?



<j:forEach var ="jvar_array" items="${diffArray}">  


      ${jvar_array}<br/>  


</j:forEach>



If you still get null, what happens when you log out the array in line 22 with:


JSUtil.logObject(diffArray);


View solution in original post

3 REPLIES 3

Brad Tilton
ServiceNow Employee
ServiceNow Employee

Have you tried the following for lines 29-32?



<j:forEach var ="jvar_array" items="${diffArray}">  


      ${jvar_array}<br/>  


</j:forEach>



If you still get null, what happens when you log out the array in line 22 with:


JSUtil.logObject(diffArray);


Using your suggestion for lines 29-32 did the trick. Looks like I overcomplicated things from the beginning.



Thank you!!


@Brad Tilton 

 

It is working ,Thank you 🙂