How to use jelly variable in javascript / glide?

Deepak Ingale1
Mega Sage

Hello All,

I am building one page for room booking application.

What I am trying to do is to find the available rooms when user selects 'requested from' and 'requested till' fields (both are glide datetime).

I am passing these fields using getWindowProperties() function to variable "jvar_my_variable" as seen below. It is highlighted in bold.

What is happening is that, When I use this variable in the g:evaluate tag which is also highlighted, I see that this variable contains null value rather than actual datetime value. I have also attached the screenshot for reference.

Can any 1 help me in troubleshooting this issue why I am not able to see actual date time and seeing at null value?

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

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

<head>

<style>

#myIdDiv{

  width:800px;

  margin:50px;

}

#mydoc{

  margin:50px auto;

  width:100px;

}

#mydiv{

  background:maroon;

  color:white;

  height:20px;

  text-align:center;

}

#mytable{

  border-collapse:collapse;

  border:1px solid black;

  width:100%;

}

#mydata, #myrow{

  width:auto;

  border-collapse:collapse;

  border:1px solid black;

  text-align:center;

}

</style>

</head>

<div id="myIdDiv">

<div id="mydiv">Welcome to Status Checker</div>

  <g:ui_form>

  <!-- Get values from dialog preferences passed in -->

    <g:evaluate var="jvar_my_variable"

    expression="RP.getWindowProperties().get('my_variable')" />

  </g:ui_form>

  <g:evaluate>

    var gr = new GlideRecord('u_book_room');

    gr.addQuery('status','Booked');

    gr.orderBy('u_room');

    gr.query();

  </g:evaluate>

  <table id="mytable">

    <th id="header1" colspan="6">Room Status</th>

    <tr id="myrow">

    <td id="mydata">Request Number</td>

    <td id="mydata">Room Number</td>

    <td id="mydata">Status</td>

    <td id="mydata">Requested From</td>

    <td id="mydata">Requested Till</td>

    <td id="mydata">Current Record Time</td>

    </tr>

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

      <g:evaluate   jelly="true">

        var diffStart = gs.dateDiff(gr.getDisplayValue('u_requested_from'), jelly.jvar_my_variable,true);

        gs.addInfoMessage(gr.getDisplayValue('u_requested_from') + " " +   jelly.jvar_my_variable);

        gs.addInfoMessage('Hello ' + diffStart);

      </g:evaluate>

      <j:if test="${diffStart &gt; 0}">

        <tr id="myrow">

        <td id="mydata"><a href="u_book_room.do?sys_id=${gr.getDisplayValue('sys_id')}">${gr.getDisplayValue('u_number')}</a></td>

        <td id="mydata">${gr.getDisplayValue('u_room')}</td>

        <td id="mydata">${gr.getDisplayValue('u_status')}</td>

        <td id="mydata">${gr.getDisplayValue('u_requested_from')}</td>

        <td id="mydata">${gr.getDisplayValue('u_requested_till')}</td>

        <td id="mydata"> ${jvar_my_variable} </td>

        </tr>

      </j:if>

    </j:while>

  </table>

</div>

</j:jelly>

7 REPLIES 7

Kalaiarasan Pus
Giga Sage

I am not a Jelly expert but it seems '$' is missing ...



<g:evaluate var="jvar_my_variable" expression="${RP.getWindowProperties().get('my_variable')}" />


Hello Kalaiarasan,



That expression is correct actually. I found the issue.


I forgot to pass on the form field value in the UI action responsible for rendering this UI page.


Anyways, thank you for your reply


Harish Murikina
Tera Guru

Hi Deepak,



            I did it in demo but i passed hard coded value to parameters. If you send your ui action code that would be fien to understand what your passing exactly.



click below link to Login demo


ServiceNow


uname and pwd : admin




booking status.JPG



Hello Harish


Here is my UI action code



It is client callable. and appears in the form of button.



function myFunction()


{


    var myVariable = g_form.getValue('u_requested_from'); // get value from form field and store it in variable


    var gwin = new GlideDialogWindow('Here it the name of UI page');


// Passing myVariable value which is 'requested from' field to 'my_variable' in the UI page


// Code for it is in the UI page which is denoted by next two lines


// <g:evaluate var="jvar_my_variable"


//   expression="RP.getWindowProperties().get('my_variable')" />


  gwin.setPreference('my_variable', myVariable); //This passes value from form to UI page


gwin.setSize(750,400);


gwin.render();


}