UI macro condition

e_wilber
Tera Guru

I have added a UI button to my KB form as found on https://community.servicenow.com/community?id=community_question&sys_id=32bbcba1db9cdbc01dcaf3231f96....

I added the following code to my macro and it works great.

<button id="email_client_open" onclick="popupOpenEmailClient('email_client.do?sysparm_table=kb_knowledge&amp;sysparm_sys_id=${knowledgeRecord.sys_id}&amp;sysparm_target=kb_knowledge&amp;sys_target=kb_knowledge&amp;sys_uniqueValue=${knowledgeRecord.sys_id}')" src="images/icons/email.gifx" aria-label="Email" class="btn btn-icon icon-mail" title="" data-original-title="Email"></button>

There is a checkbox on the knowledge article that indicates when this button should appear and I can't for the life of me figure out how to conditionally show this button.  If the field on the form was named u_cb and we wanted to show this only if it's checked, how do I wrap this button in that condition?

 

3 REPLIES 3

Mike Allen
Mega Sage

Maybe an onLoad client script where you use DOM manipulation, so:

 

if(g_form.getValue('u_cb') == false){

document.getElementById("email_client_open").style.visibility = "hidden";

}else{

document.getElementById("email_client_open").style.visibility = "visible";

}

 

My apologies I should have been more clear. This notification button is within a UI macro page where everything is code, it's not on a form directly so I can't use client scripts.

Ian Mildon
Tera Guru

You can encode it directly in the UI Macro. As an example, here is a section of code I added to the kb_view_common_footer macro to add a navigation button, but only for KB articles flagged as "customer facing" (which is a checkbox on the knowledge form) and in a specific Knowledge Base

<j:choose>
	<j:when test="${knowledgeRecord.u_customer_facing == true &amp;&amp; knowledgeRecord.kb_knowledge_base == 'a7e8a78bff0221009b20ffffffffff17'}">
		<table style="width: auto; background-color: #ffffff; margin-left: auto; margin-right: auto;">
        <tbody>
        <tr>
        <td>
        <a href = "sp?id=index"><h3 style="text-align: center; color: #4B9CD3"> MySupport@UNC Homepage </h3></a>
        </td>
        </tr>
        </tbody>
        </table>
		</j:when>
	</j:choose>