The CreatorCon Call for Content is officially open! Get started here.

Query a table from a UI page

Jon23
Mega Sage

I would like to create a form that will allow users to enter some information (name) which will then be used to query a table and return the results.

 

Looking at the wiki/forum it appears that a UI Page is a good option for this (correct me if i'm wrong).


Not being familiar with UI Pages and Jelly I am looking for some pointers/sample code on how to achieve this.

7 REPLIES 7

hi brian.



I actually ended up getting help when I attended the Knowledge14 pre-conference training. When i say help, the ServiceNow expert basically wrote the whole thing in about 15 minutes.



The code used to create the UI page was above my understanding so never made it to production as I didn't feel confident in supporting it if updates were required, however, it does work as I intended



Here is the code of the UI page for your reference - hope it helps:



HTML:


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




<p><b>Mobile Phone Eligibility Checker</b></p>




  <input type="hidden" name="check_or_cancel" id="check_or_cancel" value=""/>


  <input type="hidden" name="start_error" id="start_error" value="false"/>


  <input type="hidden" name="end_error" id="end_error" value="false"/>




    <!-- Set up form fields and labels -->


    <table width="50%">


        <tr id="description_row" valign="top">


              <th colspan="6">


                    ${jvar_short_text}


              </th>


        </tr>




      <tr>


            <td>


                    <span id="mandatory" class="mandatory_populated label_description" colspan="1">&#160;</span>


                    ${gs.getMessage("Cell User")}:


            </td>




              <g:evaluate var="jvar_request">


              var appUser = new GlideRecord("u_cell_user");


                            appUser.addQuery("sys_id", "${jvar_cellUser}");


                            appUser.query();


                            appUser.next();


                            appUser;


            </g:evaluate>




            <td>


                    <j:if test="${jvar_cellUser !=''}">


                        <g:ui_reference mandatory="true" name="cellUser" table="sys_user" value="$[appUser.sys_id]" displayValue="$[appUser.user]" />


                    </j:if>


                    <j:if test="${jvar_cellUser ==''}">


                        <g:ui_reference mandatory="true" name="cellUser" table="sys_user" />


                    </j:if>


                   


            </td>


      </tr>




        <tr id="dialog_buttons">


              <td colspan="6" align="right">




                    <input type="hidden" name="current_sys_id" value="${RP.getWindowProperties().get('sys_id')}"/>


                    <input type="submit" id="check" onclick="return check();" title="${gs.getMessage('Will Check Eligibility')}" value ="${gs.getMessage('Check Eligibility')}" style="background-color: #777777; color: white; margin-right:4px; font-weight: bold;" />




                  <input type="submit" id="cancel" onclick="return cancel();" title="${gs.getMessage('Cancel')}" value ="${gs.getMessage('Cancel')}" style="background-color: #777777; color: white; font-weight: bold; margin-right:4px;"/>




            </td>


        </tr>


  </table>


</g:ui_form>




</j:jelly>




Client Script:


function check() {


      if(!cellUser()){


              alert (getMessage('Please choose an approver to review and approve your renewal contract'));


              return false;


      }


      var c = gel('check_or_cancel');


      c.value = "check";


  return true;


}




function cancel() {


      var c = gel('check_or_cancel');


      c.value = "cancel";


      return true;


}




document.observe("dom:loaded", function() {


  $("check").observe("click",function(event){


  event.stop();


  window.location="u_cellusage_list.do?sysparm_query=u_user=" +$F("cellUser");


  return false;


  })


});




Processing Script:


if(check_or_cancel == "check") {


      response.sendRedirect("<instanceURL>/<table>.do?sysparm_query=u_user=<sys_ID>");


}






if(check_or_cancel == "cancel") {


      var urlOnStack = GlideSession.get().getStack().bottom();


      response.sendRedirect(urlOnStack);


}


Thanks so much! I'll give this a whirl and see how it does.


Thanks a lot !


Checco