how to populate value in drop down from database using jelly script

msmmithlesh
Tera Contributor

hi guys

i want to populate my location value in a drop down from location table and on click of submit i want to select that value so would you pls share jelly script for this..

thanks in advance

1 ACCEPTED SOLUTION

guhann
Mega Guru

Hi Mithlesh,



Since you are asking for jelly script I hope you are trying this in a UI Macro or UI Page. For pulling values from database and load the drop-down options see below code in bold.



<?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_location" object="true">


          var location = new GlideRecord('cmn_location');


  //location.addQuery('country','USA'); //Give the query filter condition if any as per your requirement


  location.query();


  location;


  </g:evaluate>



  <select id="location">


  <option value="">-- None --</option>


  <j:while test="${jvar_location.next()}">


  <option value="${jvar_location.getValue('name')}">${jvar_location.getValue('name')}</option>


                </j:while>


  </select>


</j:jelly>



And you also mentioned that you want to select the value on Submit. In case if you using this macro in a catalog item form, you can do that from an onSubmit catalog client script on the relevant catalog item level.


View solution in original post

9 REPLIES 9

Have you got any solution for reference field?

bernyalvarado
Mega Sage

In there there's various combo box, but in particular the following code should be helpful:



<g2:evaluate>


                    var views = new GlideRecord('map_view');


                    views.orderBy('name');


                    views.query();


              </g2:evaluate>


  <tr>




  <td nowrap="nowrap" align="right">


                                      <label for="map_ciview">${gs.getMessage('View')}:</label>


                              </td>




  <td>



<select name='map_ciview' id='map_ciview' style='width: 200px; overflow: auto;'>


  <option value=''> ${gs.getMessage('All')} </option>




  <j2:while test="$[views.next()]">


                                                      <g2:evaluate>


                                                            var viewHasRole = false;


                                                            var roles = views.roles.split(',');


                                                            if (roles.length != 0) {                


                                                                  for (var i=0; i != roles.length; i++) {


                                                                        if (gs.hasRole(roles[i])) {


                                                                              viewHasRole = true;


                                                                              break;


                                                                        }


                                                                  }


                                                            }


                                                            else


                                                                  viewHasRole = true;


                                                      </g2:evaluate>


                                                      <j2:if test="$[viewHasRole]">


                                                            <option value='$[views.sys_id]'> $[views.getValue("name")]</option>


                                                      </j2:if>


                                      </j2:while>


  </select>



Thanks,


Berny


i have one more dout i want to set a reference field on my custom table from my location table ..means the value which select from drop down its should update in my custom table column which is a reference field


Hi Mithlesh,



In this case, when you populate the options for your drop-down give the sys_id as value instead of name of the location. So that you easily get the selected value and map it to your custom table field refering to location table.


Hi, just out of curiosity, is your UI page some sort of maintenance window for records of a table?



Thanks,


Berny