populate select box from glide record

techies
Kilo Expert

Hello all,

        So I am creating a UI page that requires a select box to become populated with values that are stored inside a custom table. The custom table

        has a column that contains a 'choices field' with several different choices. I am wondering if there is a way to get an array of these values into the

        jelly script and use it in the select box. An example would be lovely too.

Thank you for any help.

1 ACCEPTED SOLUTION

Here you go



<g:evaluate var="jvar_test" object="true" jelly="true">


var obj=[];


var gr= new GlideRecord('u_sales_order_ui');


  gr.query();


  while(gr.next()){


obj.push(gr.u_subcategory.toString());


  }


  obj;


</g:evaluate>


<select>


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


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


  </j:forEach>


</select>


View solution in original post

19 REPLIES 19

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Roni,



here is one example



html section of ui page



Select the fields:


  <select name="dynamicColumns" id="dynamicColumns" multiple="multipe" style="display:none">


  </select><br/>



client script of ui page



var select = document.getElementById('dynamicColumns');


  document.getElementById("dynamicColumns").options.length=0;


  var gr1 = new GlideRecord('incident');


//   gr1.addQuery('column',);


  gr1.query();


  while(gr1.next()){


  var opt = document.createElement('option');


  opt.value = gr1.category;


  opt.innerHTML = gr1.category;


  select.appendChild(opt);


  }


 


  document.getElementById('dynamicColumns').style.display = '';



this example will create a drop down with categories present in incident table



Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.


Thanks


Ankur


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

This would only work if there are elements to be able to query from in the table. But I only want the values from the choices field in category.


Something like this in the HTML will work



<g:evaluate var="jvar_test" object="true" jelly="true">


var obj=[];


var gr= new GlideRecord('sys_choice');


  gr.addQuery('nameSTARTSWITHincident^element=category');


  gr.query();


  while(gr.next()){


obj.push(gr.label.toString());


  }


  obj;


</g:evaluate>


<select>


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


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


  </j:forEach>


</select>


Hi Thanks for the response!


It seems to work for that table but how do I create a column in my table to achieve the same result. I cannot seem to find the 'category' column in 'sys_choice' to copy the same column.