Dynamic Content Blocks

Patrick Quinlan
Giga Guru

I am attempting to build a Dynamic Content block to act as an interactive filter. I am trying to construct an assignment group select input that derives it's values from the sys_user_groups table. I feel like I am extremely close to getting this to work, however the only choices that it builds into the select input all state "org.Mozilla.javascript.nativearray....."

It doesn't appear to pull the actual names of the groups from the table. Below is the code that I'm starting with. Obviously, once I can get this portion of code working, I will build on it. Can anyone assist?

<?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:evaluate var="jvar_test" object="true" jelly="true">

        var obj=[];

        var gr= new GlideRecord('sys_user_group');

            gr.query();

            while(gr.next()){

                  obj.push(gr.name.getDisplayValue());

            }

        obj;

</g:evaluate>

<select name="AGroup">

  <j:forEach items="${jvar_test}">

          <option value="${jvar_test}"> ${jvar_test} </option>

  </j:forEach>

</select>      

</j:jelly>

1 ACCEPTED SOLUTION

Geoffrey2
ServiceNow Employee
ServiceNow Employee

The main issue is you're missing the var attribute in the forEach loop. items is your Array, and var defines the variable for the individual items in the array.


Think of it like this:



for (jvar_choice in items) {


        // Do stuff


}



<?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:evaluate>


                  var obj = [];


                  var gr= new GlideRecord('sys_user_group');


                  gr.query();


                  while(gr.next()) {


                            obj.push(gr.name.getDisplayValue());


                  }


        </g:evaluate>



        <select name="AGroup">


                  <j:forEach var="jvar_choice" items="${obj}">


                            <option value="${jvar_choice}">${jvar_choice}</option>


                  </j:forEach>


        </select>    



</j:jelly>


View solution in original post

10 REPLIES 10

Geoffrey2
ServiceNow Employee
ServiceNow Employee

The main issue is you're missing the var attribute in the forEach loop. items is your Array, and var defines the variable for the individual items in the array.


Think of it like this:



for (jvar_choice in items) {


        // Do stuff


}



<?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:evaluate>


                  var obj = [];


                  var gr= new GlideRecord('sys_user_group');


                  gr.query();


                  while(gr.next()) {


                            obj.push(gr.name.getDisplayValue());


                  }


        </g:evaluate>



        <select name="AGroup">


                  <j:forEach var="jvar_choice" items="${obj}">


                            <option value="${jvar_choice}">${jvar_choice}</option>


                  </j:forEach>


        </select>    



</j:jelly>


geoffrey.sage



Thank you for the quick reply. Your solution was exactly what I needed.


Follow up question.....


Is it possible to pass a variable to the GlideRecord query from another select statement?


Probably.   What is the scenario?