We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

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

bernyalvarado
Mega Sage

Hi Mithlesh,



You can refer to the OOB UI page bsm_options_dialog



Thanks,


Berny


bernyalvarado
Mega Sage

The URL of the UI Page for it should be something like the following:



https://yourinstancename.service-now.com/nav_to.do?uri=sys_ui_page.do?sys_id=ec675c930a0a0b3a00d0ebe...



Thanks,


Berny


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.


thanks Guhan its working but 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