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

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

If i'm understanding what you're saying, then I'd add this code after the query but before the while loop:


<j2:set var="jvar_count" value="$[inc.getRowCount()]"/>



Then add this after the table close:


Total records:   $[jvar_count]<br/>


Thank you Kristen !


Its working good.


Hi ,


Requirement: Create two fields of type "glide_duration" namely "Actual duration" and "Estimated


Duration " . Show their differences in hours in an alert on save or update operation



I've created script include and client script. but am getting null in alert.


script include:


var Time_Difference = Class.create();


Time_Difference.prototype = Object.extendsObject(AbstractAjaxProcessor, {


getDateTimeDiff: function(){  



var firstDT = this.getParameter('sysparm_fdt');


gs.log("First Date "+ firstDT);


var secondDT = this.getParameter('sysparm_sdt');


var diffTYPE = this.getParameter('sysparm_difftype');


var diff = gs.dateDiff(firstDT, secondDT, true);  



var timediff = this._calcDateDiff(diffTYPE, diff);  


gs.log("Test.."+timediff);


return timediff;  


},  


      type: 'Time_Difference'


});



client script:


function onSubmit() {


   


var actual = g_form.getValue('u_actual_duration');


var expected = g_form.getValue('u_estimated_duration');  


var dttype = 'day'; //this can be day, hour, minute, second. By default it will return seconds.  


 


var ajax = new GlideAjax('Time_Difference');  


ajax.addParam('sysparm_name','getDateTimeDiff');  


ajax.addParam('sysparm_fdt',actual);  


ajax.addParam('sysparm_sdt',expected);  


ajax.addParam('sysparm_difftype',dttype);  


ajax.getXML(doSomething);  


 


function doSomething(response){  


var answer = response.responseXML.documentElement.getAttribute("dttype");  


alert(answer);  


}  




}


Hi Haritha,



I couldn't see any line of code which sends the date from first UI page to 2nd UI page.



Approach:


Send start date and end date to the 2nd ui page and have GlideRecord in 2nd UI page and generate HTML table.



UI Page 1



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;



// check whether value is getting


alert('Start Date is: ' + date1);


alert('End Date is: ' + date2);



// you got the date now call GlideDialogWindow for 2nd UI page and pass these 2 values



var dialog = new GlideDialogWindow("second_ui_page"); // set proper name of second ui page here


    dialog.setTitle("Incident");


    dialog.setPreference("start_date", date1); // send start date


    dialog.setPreference("end_date", date2); // send end date


    dialog.render();


}



function MyFunction2(){


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


}



UI Page 2



HTML Section



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


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



<j:set var="jvar_start_date" value="${RP.getWindowProperties().get('start_date')}" />


<j:set var="jvar_end_date" value="${RP.getWindowProperties().get('end_date')}" />



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


var createdOnEncodedQuery = "sys_created_onBETWEEN" + jelly.jvar_start_date + "@" + jelly.jvar_end_date;


var gr = new GlideRecord('incident');


gr.addEncodedQuery(createdOnEncodedQuery);


gr.query();


gr;


</g:evaluate>



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


<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> ${jvar_gr.number}</td>


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


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


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


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


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


</tr>


</table>


</j:while>


</j:jelly>



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