Need Jelly Help - Conditionally display a UI Macro

perkinsarm
Mega Guru

I need show some HTML content on a form but only when the the record is of a certain type. This is a scoped application. The HTML content includes formatted instructions and links to more detailed knowledge articles and external company content. I need to do this in multiple places on the form.

We are still on Fuji.

I tried annotations. There is a bug that causes their content to get corrupted if you have more than one html annotation in a form section (I need three).

A UI-Macro formatter solves the display corruption problems, but I've had trouble hiding them on forms where they should not be shown.

Unfortunately, a UI Policy can only hide fields.

I have placed in id in the html and tried to hide them via DOM manipulation w/o luck in an onLoad client script.

Since they are already based on Jelly the last possible solution would be to add logic that would hide them if the record, an Engineering Work Order (EWO) is not the EWO Type where they need to be displayed (We have half a dozen EWO types and each forms vary baed on type).

Here is what I have tried. What I'm trying to do is determine the record type based on the ewo_type field and set the display attribute of the table to either 'none' or 'block'. I'm a Jelly novice, but have a lot of Javascript, HTML, CSS experience.

What am I missing?

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

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

      <table class="" style="width: 100%; display:displayType('Data Project')" id="u_ds_err_hlp_tbl">

              <tbody>

                      <tr data-annotation-type="Info Box Red" class="annotation-row" style="display: table-row;">

                              <td colspan="99" data-annotation-type="Info Box Red" class="annotation">

                                      <div class="annotation-wrapper" style="padding:2px 0px 0px 4px; direction:ltr;">

  <div style="border:none; padding: 0px;">Use our&#160;<a href="http://www.example.com/example/#v/tool/s/" target="_blank"> Discovery Tool</a>&#160;to check datastream names and start and end dates.</div>

                                      </div>

                              </td>

                      </tr>

              </tbody>

      </table>

  <script>

  function displayType(ewo_type)

  var displayed = 'none';

  if(g_form.ewo_type == ewo_type) {

  displayed = 'block';

  }

        gs.log(displayed);

  return displayed;

  }

  </script>

</j:jelly>

5 REPLIES 5

Shahed Shah1
Tera Guru

Hi Bradley



I take it that the field of interest is ewo_type. How about using the "g:set_if"syntax, to create a variable (like jvar_display). In the test you can use the GlideRecord API with the current object, so you can test current.getValue("ewo_type") then use that Jelly variable in the style attribute of the tr (i.e. style="display: ${jvar_display}").



Hopefully this sets you in the right direction.



Shahid


Shahid,


Your suggestion is helpful and has me on the right track but I'm still not getting my desired result. The content is now hidden for all record types, therefore my g:setif 'test' must be always evaluating to false. This is likely due to me unfamiliarity with the Jelly syntax. Any abbreviated example is below.



<?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:set_if var="jvar_displayed" test="${jvar_gr.current.ewo_type =='Data Project'}" true="block" false="none" />


      <table class="" style="width: 100%; display:${jvar_displayed}" id="u_ds_hlp_tbl">


      </table>


</j:jelly>



How should that test be written to see if current.ewo_type == 'Data Project'?


You can utilise the g:breakpoint tag and put it where you need it. An example to debug the value of a variable is:


<g:breakpoint var="jvar_displayed" />



Navigating to Session Debug > Debug Log will present useful debug at the bottom of a form and you can observe the value there. You can even debug expressions (like the test in the Jelly code).



Upon quick read of the code, I see jvar_gr. Have you defined this anywhere? I think you may get the desired output by removing this, so just keep "current.ewo_type = ..."


I had not defined jvar_gr. I'd seen it in examples. I removed it.


However, test=${current.ewo_type=='Data Project'} doesn't evaluate true when a Data Project record is displayed.



<g:breakpoint var="jvar_displayed" /> always shows 'none'.