UI Macro g2 evaluate not processing

amkatulak
Giga Expert

Hello,

I am trying to embed a PDF file into an approval_summarizer for the dms_document_revision table.   I have a g2: evaluate expression that is running a GlideRecord query against the attachment table.   When I do a 'while loop', the while test processes, but my variable does not return a result.   I'm pretty inexperienced with Jelly and am not sure what could be going wrong.   Here's my code.

 

<g2:evaluate expression="var pdf_attach = new GlideRecord('sys_attachment'); pdf_attach.addQuery('table_name','dms_document_revision'); pdf_attach.addQuery('content_type','application/pdf'); pdf_attach.addQuery('table_sys_id','$[current.document_id]'); pdf_attach.query(); " jelly="true" var="pdf_attach"/>
   <j2:if test="$[pdf_attach.hasNext()]">
   <j2:while test="$[pdf_attach.next()]">
   <embed height="$[gs.getProperty('glide.kb.pdf.height')]" src="/sys_attachment.do?sysparm_referring_url=tear_off&amp;view=true&amp;sys_id=$[pdf_attach.sys_id]" type="application/pdf" width="$[gs.getProperty('glide.kb.pdf.width')]"/>
   <br/>
   </j2:while>
   </j2:if>

Thanks!

3 REPLIES 3

kyleb13281
Kilo Expert

Do away with the expression and throw your script within the <g2:evaluate> tag like this:



<g2:evaluate jelly="true" var="pdf_attach"/>  


          var pdf_attach = new GlideRecord('sys_attachment');


          pdf_attach.addQuery('table_name','dms_document_revision');


          pdf_attach.addQuery('content_type','application/pdf');


          pdf_attach.addQuery('table_sys_id','$[current.document_id]');


          pdf_attach.query();


          while (pdf_attached.next()){


                      var attach;


                      //do your thang!


                      attach = pdf_attach.variable; //make attach == which ever   variable you are getting


          }


            attach; //this will return your answer to the jelly var (in this case: var="pdf_attach")


</g2:evaluate>


Thanks Kyle, but I still can't get it to work.   My script is actually showing up as text within my frame at this point.   I'm not sure why it would do that.   Here's the updated code.   I'm trying to utilize the approval_summarizer macro and add to it, but if I need to go a different route, let me know as well.



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


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


  <g:evaluate var="jvar_has_source" >


      var flag = !${ref}.sysapproval.nil() || !${ref}.source_table.nil();


      flag;


  </g:evaluate>


  <j:if test="${jvar_has_source}">


      <g:evaluate var="jvar_ni" expression="


      var gr = null;


              if ( !${ref}.source_table.nil()) {


                    gr = new GlideRecord(${ref}.source_table);


                                      gr.get( ${ref}.document_id);


                              } else {


                                      gr = new GlideRecord('task');


                                      gr.get(${ref}.sysapproval);


                              }


              " />


      <g:evaluate>


              g_approval_form_request = true; // this global is checked in ACLs


      </g:evaluate>


      <g:evaluate var="jvar_my_form">


              var gc =   new GlideController();


              var p =   new GlidePopup(gc, "${gr.sys_class_name}");


              p.putParameter("sys_id", "${gr.sys_id}");


              p.putParameter("sysparm_view", "approval");


              //PRB579164: Skip g_form creation in activities.xml if activities displayed in formatter


              p.putParameter("sysparm_skip_gform", "true");


              var rp = p.getRenderProperties();


              rp.setSmallCaption(true);


              var s = p.getPopup();


              s;


      </g:evaluate>


  <g2:evaluate var="jvar_pdf_attach" jelly="true">


  var pdf_attach = new GlideRecord('sys_attachment');


  pdf_attach.addQuery('table_name','dms_document_revision');


  pdf_attach.addQuery('content_type','application/pdf');


  pdf_attach.addQuery('table_sys_id','$[current.document_id]');


  pdf_attach.query();


  while (pdf_attach.next()) {


  var attach = pdf_attach.sys_id;


  }


  attach;


  </g2:evaluate>



  <embed height="$[gs.getProperty('glide.kb.pdf.height')]" src="/sys_attachment.do?sysparm_referring_url=tear_off&amp;view=true&amp;sys_id=$[jvar_pdf_attach]" type="application/pdf" width="$[gs.getProperty('glide.kb.pdf.width')]"/>


  <br/>


      <tr id="approval_summary_row">


              <td width="100%" colspan="2">


                      <j2:if test="${gs.getProperty('glide.security.use_csrf_token')}" >


  <input type="HIDDEN" name="sysparm_ck" value="$[gs.getSessionToken()]"/>


        </j2:if>


                      <div id="approval_summary" style="padding-top:8px;display:none;">


                <div class="caption" style="padding:4px;">${gs.getMessage('Summary of Document Revision being approved')}</div>


                <div style="padding-left:2px;"><g:no_escape>${jvar_my_form}</g:no_escape></div>


  <div style="padding-left:2px;"><g:no_escape>$[jvar_pdf_attach]</g:no_escape></div>


                      </div>




  </td>


      </tr>



      <g:evaluate>


              delete g_approval_form_request; // removes the global


      </g:evaluate>


      <script>


              addRenderEvent(moveSummaryForm);


              function moveSummaryForm() {


                      var e = $("approval_summary");


                      var form = $("sysapproval_approver.do");


                      var formParent = form.parentNode;


                      formParent.appendChild(e);


                      e.show();


              }


      </script>


  </j:if>


</j:jelly>


Change the <g2:evaluate....> tag to <g:evaluate...>, along with the corresponding closing tag. At the very least that should keep the code from appearing on your summarizer. I can't help you any further than that as I'm having a similar problem myself.