How to write if condition in Macros?

ch_naresh207
Giga Expert

Hi All,

I created two knowledge bases in my environment 1 is KEDB and 2nd is IKDB(incident knowledge database). each knowledge as a different field so thats why i created UI policys .. its ok for me in form level..

issue with

whenever i published KEDB articles ,,KEDB field is visible and   same time IKDB field is visible,,,,here we are using UI macros.. So, here how to create if condition in macros.

For example: If Knowledge base = KEDB selects visible only KEDb fields

{

                                          else knowledge base =IKDB visible only for IKDB fields

}

                                       

Please find the below script how to write IF Else condition ?

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

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

  <j:choose>

  <j:when test="${knowledgeRecord.article_type != 'wiki'}">

  <div id="article" class="snc-article-content-text">

<b>

KB Number:

</b>

<br/> <g2:no_escape>$[NS:knowledgeRecord.number]</g2:no_escape>

  <br/>

<b>

Problem Number:

</b>

<br/> <g2:no_escape>$[NS:knowledgeRecord.u_related_problem]</g2:no_escape>

  <br/>

<b>

Known Error:

</b>

<br/>     <g2:no_escape>$[NS:knowledgeRecord.u_known_error]</g2:no_escape>

  <br/>

<b>

Workaround fix:

</b>

<br/>     <g2:no_escape>$[NS:knowledgeRecord.u_workaround_fix]</g2:no_escape>

  <br/>

<b>

Permanent fix:

</b>  

<br/>     <g2:no_escape>$[NS:knowledgeRecord.u_permanent_fix]</g2:no_escape>

  <br/>

<b>

Third Party involved:

</b>  

<br/>     <g2:no_escape>$[NS:knowledgeRecord.u_third_party_involved]</g2:no_escape>

  <br/>

<b>

Support team involved:

</b>  

<br/>     <g2:no_escape>$[NS:knowledgeRecord.u_support_team_involved]</g2:no_escape>

  <br/>

<b>

Risk number:

</b>  

<br/>     <g2:no_escape>$[NS:knowledgeRecord.u_risk_number]</g2:no_escape>

  <br/>

<b>

Additional comments:

</b>  

<br/>     <g2:no_escape>$[NS:knowledgeRecord.u_additional_comments]</g2:no_escape>

  <br/>

  </div>

  </j:when>

  <j:otherwise>

  <div id="article" class="snc-article-content-text knowledge-wiki-text">

  <g2:no_escape>$[NS:glideWikiModel.render(knowledgeRecord.wiki)]</g2:no_escape>

  </div>

  </j:otherwise>

  </j:choose>

</j:jelly>

1 ACCEPTED SOLUTION

The general syntax of the if statement is like this:



<j:if test="condition" >


        <!-- this code gets run -->


</j:if>



In your case, the condition is going to be something like:



<j:if test="${kb_knowledge.kb_knowledge_base.getDisplayValue() == 'KEDB'">


<!-- Show the three fields -->


</j:if>



<j:if test="${kb_knowledge.kb_knowledge_base.getDisplayValue() == 'IKDB'">


<!-- Show the other three fields -->


</j:if>



THIS IS UNTESTED CODE. YOU NEED TO TEST AND ADJUST AS NECESSARY FOR YOUR CONDITIONS.


View solution in original post

14 REPLIES 14

ch_naresh207
Giga Expert

Hi










I'm not clear which fields are you KEDB and which are you IKDB fields and where you would like to display them. Can you include screen shots?


ch_naresh207
Giga Expert

in KEDB is     1.Known Error 2. workaround fix:   3..Permanent fix:


in IKDB is 1.Support team involved: 2. Risk number: 3. Additional comments



Please help me the how to create if else condition in macros.




once publish any article that is visible for end users self service> knowledge thats why am using UI macro.


The general syntax of the if statement is like this:



<j:if test="condition" >


        <!-- this code gets run -->


</j:if>



In your case, the condition is going to be something like:



<j:if test="${kb_knowledge.kb_knowledge_base.getDisplayValue() == 'KEDB'">


<!-- Show the three fields -->


</j:if>



<j:if test="${kb_knowledge.kb_knowledge_base.getDisplayValue() == 'IKDB'">


<!-- Show the other three fields -->


</j:if>



THIS IS UNTESTED CODE. YOU NEED TO TEST AND ADJUST AS NECESSARY FOR YOUR CONDITIONS.