Jelly Scripting to pull Unique PO numbers on the alm_hardware table

Rachel Reviczky
Tera Contributor

Hello everyone,

 

I am relatively new to Jelly scripting and working on a custom interactive filter for a dashboard we use for hardware asset management. 

I'm trying to make a drop-down where you can select multiple POs from a dropdown that displays Unique Values only.

I am so very green so I put together this following Jelly based on some AI and some ServiceNow articles:

<j:jelly xmlns:j="jelly:core" xmlns:fmt="jelly:fmt" xmlns:xml="jelly:xml" xmlns:g="glide">
    <g:log msg="Starting PO Number filter creation"/>
    <g:query table="alm_hardware" var="hardware">
        <g:select distinct="true" field="po_number"/>
    </g:query>
    <g:if test="${hardware.hasNext()}">
        <g:log msg="PO Numbers found"/>
        <select id="po_number_filter">
            <option value="">-- Select PO Number --</option>
            <g:while test="${hardware.next()}">
                <option value="${hardware.po_number}">${hardware.po_number}</option>
            </g:while>
        </select>
    </g:if>
    <g:else>
        <g:log msg="No PO Numbers found"/>
    </g:else>
</j:jelly>


 However the content block shows as being empty.

Can someone please point me in the direction of were I'm going wrong? I feel like it's pulling an empty table but I tried "PO number" "po_number" and "po&nbsp;number" and none of them turn up data. 

5 REPLIES 5

Ankur Bawiskar
Tera Patron
Tera Patron

@Rachel Reviczky 

this link has solution, please enhance

populate select box from glide record 

Also I shared solution here

UI Page - Jelly Script 

why not have reference field using g:ui_reference?

If there are lot of choices then it's not a good user experience to show huge list of drop down values

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

@Rachel Reviczky 

Hope you are doing good.

Did my reply answer your question?

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

I am trying to follow along, but as someone very new to Jelly I don't actually think I've done this correctly. I am likely making a mistake either in what I'm trying to achieve or the table name because it has a space in it perhaps?

The code I used is as follows:

<g:evaluate var="jvar_test" object="true" jelly="true">
  var obj = [];
  var gr = new GlideRecord('alm_hardware');
  gr.query();
  while (gr.next()) {
    obj.push(gr.po_number.toString());
  }
  obj;
</g:evaluate>

<select>
  <j:forEach var="jvar_item" items="${jvar_test}">
    <option value="${jvar_item}">${jvar_item}</option>
  </j:forEach>
</select>

In doing this I get a dropdown list of empty fields:

RachelReviczky_0-1738336867398.png

 



@Rachel Reviczky 

seems you are fetching records with empty po number and hence the spaces

try this

<g:evaluate var="jvar_test" object="true" jelly="true">
  var obj = [];
  var gr = new GlideRecord('alm_hardware');
   gr.addEncodedQuery('po_number!=NULL');
  gr.query();
  while (gr.next()) {
    obj.push(gr.po_number.toString());
  }
  obj;
</g:evaluate>

If my response helped please mark it correct and close the thread so that it benefits future readers.

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