calling client script inside jelly

dilini
Giga Expert

I am trying to call following client script inside dynamic jelly page. But onClick won't work.

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

-------- some script here

--------some script here

var record1 = new GlideRecord("sc_req_item");

  var sQuery1 = 'request.requested_for='+user_id+'^ORwatch_listLIKE'+user_id+'^ORrequest.opened_by='+user_id+'^active=true';

              if (bShowClosed == true ) {

  sQuery1= 'request.requested_for='+user_id+'^ORwatch_listLIKE'+user_id+'^ORrequest.opened_by='+user_id+'^active=false'

  }

  record1.addEncodedQuery(sQuery1);

  record1.orderByDesc("sys_updated_on");

  record1.setLimit(1);

  record1.query();

  while (record1.next()) {

                  var request = record1.request;

                  var item = record1.sys_id;

}

<a onclick="return popupDispList1(request,item);">View Recent Order Information</a>

<script>

  function popupDispList1(request, item) {

  var ajaxQry = new GlideAjax('BillingUtilAjax');

  ajaxQry.addParam('sysparm_name','getHtmlForBillingReport');

  ajaxQry.addParam('sysparm_ritm',request);

  ajaxQry.addParam('sysparm_req', item);

  ajaxQry.addParam('sysparm_today',(new Date()).toString());

  ajaxQry.getXML(ajaxResponse);

}

function ajaxResponse(response) {

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

  var win = window.open("", '_blank');

  win.document.body.innerHTML = answer;

  win.document.title = 'Billing Form';

  win.focus();

}

</script>

----- some script

----- some script

</g:evaluate>

</j:jelly>

3 REPLIES 3

Chuck Tomasi
Tera Patron

Is there any sign of trouble in your browser's console log?


dilini
Giga Expert

Hi Chuck,


Yes. There is error in my browser's console log.



It says "cannot find variable request"



Screen Shot 2017-04-25 at 1.52.31 PM.png



Thank you!


Dilini


That's helpful. It looks like you have your client script inside the g:evaluate tag. Everything from g:evaluate to /g:evaluate should be server code. If you want to reference the server variables in your client script, you'll need to use a JEXL expression like ${variable_name}



The important thing to remember about Jelly is that it is entirely processed on the server side before sending to the browser. The only thing you can send to the browser is HTML, CSS, and client side JavaScript. All the server side code has been run/translated/processed and does not go to your browser.



<g:evaluate>


    /// Your server code here


</g:evaluate>



<script>


// Your client script here


</script>