Phase 2 Jelly Processing in UI Macro

lgustafson
Kilo Expert

I have been creating a dynamic content block via Jelly scripting and I moved some of the code into a UI macro.   The script worked at first, but once moved into the UI macro, the script was no longer being processed correctly.   The script between the g2 tags is just being displayed by text.   I have seen this happen when a dynamic content block does not have the "two-phase" box checked, but there is no "two-phase" box to check on a UI macro as far as I know.   I have found other UI macros that use the j2 an g2 tags, so I assume two-phase processing is possible in UI macros, but I am unsure how to make it work.

 

Thanks for any help you can provide!

1 ACCEPTED SOLUTION

I ended up changing all tags in my UI macro to phase one tags.   It works fine, but I'm not sure why...perhaps because the macro is invoked in phase 2?


View solution in original post

5 REPLIES 5

Kalaiarasan Pus
Giga Sage

phase 2 processing is possible... can you paste the script here for reference ?


just do a basic contains filter on the xml field of UI macro and you will find number of macro's for reference.. most common one being the approval summary macro's..


Yes, I have located a number of UI Macros that use the j2 or g2 tags, so I am sure it is possible.   What I am wondering is if there is some extra parameter or something that I am missing in order to correctly process a UI macro in phase 2.   If it is not that, I'm not sure what else I am doing wrong to get it to look like this.



Screenshot.PNG


Here is the dynamic content block:



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


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


  <!--


          Normalize date to start on Sunday


  -->


  <g2:evaluate var="jvar_date" object="true">


      var date = new GlideDateTime (RP.getParameterValue("sysparm_date"));


      var offsetToSunday = date.getDayOfWeek();


      if (offsetToSunday == 7){


          offsetToSunday = 1;


      }


      else if (offsetToSunday ${AMP}lt; 6){


          offsetToSunday = offsetToSunday + 1;


      }


      offsetToSunday = offsetToSunday * 24 * 60 * 60 * 1000;


      date.subtract(offsetToSunday);


      date;


  </g2:evaluate>


  <!--


          Get event parameter


  -->


  <g2:evaluate var="jvar_event" object="true">


      var event = RP.getParameterValue("sysparm_event");


      event;


  </g2:evaluate>


  <!--


          Set current day of week, create iterator and start while loop


  -->


  <j2:set var="jvar_dayOfWeek" value="0"/>


  <j2:set var="jvar_iterator" value="true"/>


  <j2:while test="$[jvar_iterator]">


      <!--


              Call macro to display day of week


      -->


      <g2:macro_invoke macro="calendar_date" event="$[jvar_event]" date="$[jvar_date]" dayOfWeek="$[jvar_dayOfWeek]"/>


      <!--


              Increment day


      -->


      <g2:evaluate var="jvar_nextDay" object="true">


          var date = new GlideDateTime("$[jvar_date]");


          var oneDay = 24 * 60 * 60 * 1000;


          date.add(oneDay);


          date;


      </g2:evaluate>


      <j2:set var="jvar_date" value="$[jvar_nextDay]"/>


      <!--


              Increment day of week


      -->


      <g2:evaluate var="jvar_increment" object="true">


          var dayOfWeek = "$[jvar_dayOfWeek]";


          dayOfWeek ++;


          dayOfWeek;


      </g2:evaluate>


      <j2:set var="jvar_dayOfWeek" value="$[jvar_increment]"/>


      <!--


              Check if day of week is 7


      -->


    <g2:evaluate var="jvar_iTest" object="true">


        var iterator = true;


        if ("$[jvar_dayOfWeek]" == 7){


            iterator = false;}


        iterator;


      </g2:evaluate>


  <j2:set var="jvar_iterator" value="$[jvar_iTest]"/>


  </j2:while>


</j:jelly>



Here is the ui macro being called:



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


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


  <!--


          Create query for all appointment slots that match the selected event


  -->


  <g2:evaluate var="jvar_aptSlots" object="true">


      var aptSlots = new GlideRecord("u_appointment_slot");


      aptSlots.addQuery("u_event", "=", "$[jvar_event]");


      aptSlots.orderBy("u_time_start");


      aptSlots.query();


      aptSlots;


  </g2:evaluate>


  <!--


          Check each record for match to iterator's current date


  -->


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


      <g2:evaluate var="jvar_dateDiff" object="true">


          var date = new GlideDateTime("$[jvar_date]");


          var difference = gs.dateDiff("$[aptSlots.u_date.u_date]", date, true);


          var dateDiff = false;


          if (difference == 0){


              dateDiff = true;}


          dateDiff;


      </g2:evaluate>


      <!--


              Check if date is a match


      -->


      <j2:if test="$[jvar_dateDiff]">


          <!--


                  Create button text


          -->


          <g2:evaluate var="jvar_text" object="true">


              var text = aptSlots.u_time_start.getDisplayValue() + " - " + aptSlots.u_time_end.getDisplayValue();


              text;


          </g2:evaluate>


          <!--


                  Create button link


          -->


          <g2:evaluate var="jvar_link" object="true">


              var link = gs.getProperty('glide.servlet.uri') + "nav_to.do?uri=u_appointment_slot.do?sys_id=" + aptSlots.sys_id;


              link;


          </g2:evaluate>


          <!--


                  Invoke macro with parameters


          -->


          <br>


              <g2:macro_invoke macro="appointment_box" text="$[jvar_text]" link="$[jvar_link]"/>


          </br>


      </j2:if>


  </j2:while>


</j:jelly>




All script between the g2 tags are displayed as text only.