Jelly code in UI Page

Haritha Kotturi
Giga Contributor

I've created UI page to display record of incident table. But am not getting the values of state & short description fields.

Here is the code:

<tr>

  <td> ${gr.number}</td>

  <td> ${gr.caller_id.getDisplayValue()} </td>

  <td> ${gr.category} </td>

  <td> ${state.getDisplayValue()} </td>

  <td> ${short_description.getDisplayValue()} </td>

  </tr>

1 ACCEPTED SOLUTION

Ok, I had to mess around with it a bit, but this is working for me:



First UI Page:


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">


Start Date:<g:ui_date name="start_date" id="start_date" table="incident" field='sys_created_on'/> <br/><br/>


End Date:<g:ui_date name="end_date" table="incident" field='sys_created_on'/>


<br/>


<br/>


<button onClick = "MyFunction()"> Ok </button>


<button onClick = "MyFunction2()"> Cancel </button>


</j:jelly>


Client script:


function MyFunction(){


var date1 = gel("start_date").value;


var date2 = gel("end_date").value;


var nums = '';


var gr = new GlideRecord('incident');


gr.addQuery('sys_created_on','>=',date1);


gr.addQuery('sys_created_on','<=',date2);


gr.query();


while(gr.next()){


nums += ',' + gr.getValue('number');


}


window.open("date_range_selected_incident.do?sysparm_nums="+nums);


}


function MyFunction2(){


window.open("Date_Range_selecting_incident",target="_self");


}




Second UI page:


<?xml version="1.0" encoding="utf-8" ?>


<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">


<style>


table {


font-family: arial, sans-serif;


border-collapse: collapse;


width: 50%;


}




tr, td {


border: 1px solid #dddddd;


text-align: left;


padding: 8px;


}


</style>


<body>


<table>


<tr>


  <th>Incident Number </th>


  <<th> Caller </th>


  <th> Opened </th>


  <th> Opened by </th>


  <th> Assigned to</th>


<th> Priority</th>


<th> State </th>


<th> Short Description </th>


</tr>


<g2:evaluate var="jvar_incident" jelly="true" object="true">


var inc = new GlideRecord('incident');


inc.addQuery('number','IN',jelly.sysparm_nums);


inc.query();


</g2:evaluate>


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


<tr>


<j2:set var="jvar_num" value="$[inc.number]"/>


<j2:set var="jvar_caller" value="$[inc.caller_id.getDisplayValue()]"/>


<j2:set var="jvar_opened" value="$[inc.opened_at.getDisplayValue()]"/>


<j2:set var="jvar_openedby" value="$[inc.opened_by.getDisplayValue()]"/>


<j2:set var="jvar_assigned" value="$[inc.assigned_to.getDisplayValue()]"/>


<j2:set var="jvar_priority" value="$[inc.priority.getDisplayValue()]"/>


<j2:set var="jvar_state" value="$[inc.state.getDisplayValue()]"/>


<j2:set var="jvar_short" value="$[inc.short_description]"/>


<td> $[jvar_num]</td>


<td> $[jvar_caller] </td>


<td> $[jvar_opened] </td>


<td> $[jvar_openedby] </td>


<td> $[jvar_assigned] </td>


<td> $[jvar_priority]</td>


<td> $[jvar_state]</td>


<td> $[jvar_short]</td>


  </tr>


</j2:while>


</table>


</body>


</j:jelly>


View solution in original post

13 REPLIES 13

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Haritha,



Is this the only code or part of it.



Following example shows complete code and you can modify it as per your need:



it will print in tabular format the records from incident which are active=true



<g:evaluate var="jvar_gr" object="true">


    var gr = new GlideRecord("incident");


    gr.addQuery("active", true);


    gr.query();


    gr;


</g:evaluate>



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


  <tr>


  <td> ${jvar_gr.number}</td>


  <td> ${jvar_gr.caller_id.getDisplayValue()} </td>


  <td> ${jvar_gr.category} </td>


  <td> ${jvar_gr.priority} </td>


  <td> ${jvar_gr.short_description} </td>


  </tr>


</j:while>



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

Thank you.



I've created two UI pages.


->In the 1 st page create a date range selection UI, an ok button and a cancel button.


On clicking the ok button it should take the user to the next UI page.


-> In the 2 nd UI page, all the incidents created between the date range selected in 1 st


page should be shown in a tabular form-


Incident Number


Caller


Opened


Opened By


Assigned to


Priority


But am not getting the values.


Here is the code:



The 1st UI Page Code:


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">




Start Date:<g:ui_date name="start_date" id="start_date" table="incident" field='sys_created_on'/> <br/><br/>


End Date:<g:ui_date name="end_date" table="incident" field='sys_created_on'/>


  <br/><br/>


<button OnClick = "MyFunction()"> Ok </button>


<button OnClick = "MyFunction2()"> Cancel </button>  


</j:jelly>



Client Script:


function MyFunction(){


var date1 = gel("start_date").value;


var date2 = gel("end_date").value;


var createdon = "sys_created_onBETWEEN"+date1+"@"+date2;



var gr = new GlideRecord('incident');


gr.addEncodedQuery(createdon);


gr.query();


while(gr.next())


{


gr.getValue('number');


}


window.open("date_range_selected_incident.do?sysparm_inc_id="+number);


}


function MyFunction2(){


window.open("Date_Range_selecting_incident",target="_self");


}



The 2nd UI Page Code:


<?xml version="1.0" encoding="utf-8" ?>


<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">


<style>


table {


      font-family: arial, sans-serif;


      border-collapse: collapse;


      width: 50%;


}




tr, td {


      border: 1px solid #dddddd;


      text-align: left;


      padding: 8px;


}


</style>


<g:evaluate jelly='true'>


var gr = new GlideRecord("incident");


gr.get(jelly.sysparm_inc_id);


</g:evaluate>


<body>


<table>


  <tr><td>Incident Number </td>


  <td> Caller </td>


  <td> Opened </td>


  <td> Opened by </td>


  <td> Assigned to</td>


          <td> Priority</td></tr>


<tr><td> ${gr.number}</td>


  <td> ${gr.caller_id.getDisplayValue()} </td>


  <td> ${gr.opened_at} </td>


  <td> ${gr.opened_by.getDisplayValue()} </td>


  <td> ${gr.assigned_to.getDisplayValue()} </td>


  <td> ${gr.priority}</td>


  </tr>


</table>


</body>


</j:jelly>


If the code is as displayed in your original post, then you're missing the gliderecord variable (${state.getDisplayValue()}   vs. ${gr.state.getDisplayValue()} ).


I've another problem.


can you please help me.