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

Hi Abhinav,,



As you aware the above code for knowledge base,



I need small help again,



I rejected approvals in knowledge article, the rejected article also is visible in end users in self service.



I need to control only visible approvals articles.



Please suggest me where i need change the above code.



Regards,


Naresh


What do you mean by rejected article. i am not familiar with the knowledge articles. Is there any field on the knowledge form for the approval;l or is it based on the workflow field?


Yes I maintained Approvals filed, thoses approvals has been called in workflow.



one more ,by default knowledge base owner also able do approve. that means either approver or knowledge base owner do the approvals.


What happens when an article is approved or rejected? Does the Workflow field on the form change its state? I want something on the knowledge form so that I can write conditions based on that.


ch_naresh207
Giga Expert

Hi Abhinav/ chuck,



As you aware the above code for knowledge base,



I need small help again,



I rejected approvals in knowledge article, the rejected article also is visible in end users in self service.



I need to control only visible approvals articles.



Please suggest me where i need change the above code.



Regards,


Naresh