Creating new UI Macros for KB_view
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-04-2014 08:56 AM
I want to add a custom list like "Attached Tasks" to the bottom of knowledge articles. I have made changes to the "Attached Tasks" UI Macro and added my own macro to the kb_view UI Page. But my it isn't working. I am very new to Jelly and I think I understand what I did but I don't understand it enough to troubleshoot my own script.
My script is very similar to the "Attached Tasks" macro. The only major difference is that it glides to a different m2m table and is going to be a list of Catalog Items instead of Tasks.
I have commented out the JavaScript at the bottom of the UI Macro. It was on the "Attached Tasks" script but I don't think it's necessary so I commented it out. I have also tried running the script with it uncommented and it still is not working.
Please if anybody can look over this and let me know I would be extremely grateful.
UI Macro (kb_attached_changes)
<?xml version="1.0" encoding="utf-8" ?> <j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null"> <!-- list of STD items to which this MOP has been attached --> <j:set var="jvar_kb_show_items" value="${gs.getProperty('glide.knowman.recent_tasks.display','true')}"/> <!-- if recent_tasks are allowed to display these items are allowed --> <j:if test="${jvar_kb_show_items}"> <j2:if test="${gs.hasRole('itil') || gs.hasRole('knowledge')}"> <j2:set var="jvar_t" value="$[kb.sys_id]" /> <!-- Query to the m2m table, find the KB title, sort by when the cat item was created --> <g2:evaluate var="items" jelly="true" expression=" var items = new GlideRecord('u_m2m_kb_ci'); items.addQuery('u_mop_article', jelly.jvar_t); items.orderByDesc('u_catalog_item.sys_created_on'); items.setLimit(gs.getProperty('glide.knowman.recent_tasks',10)); items.query(); "/> <!-- if there are cat items show the Standard Changes title and the standard changes for this MOP --> <j2:if test="$[items.hasNext()]"> <tr id="recent_tasks"> <td width="99%" class="label label_spacing" style="background-color:#eeeeee;"> <span style="margin-right:3px; margin-left:1px;">$[SP]</span>Standard Changes:</td> <td> <j2:set var="jvar_has_real_tasks" value="false"/> <j2:while test="$[items.next()]"> <g2:evaluate var="jvar_task_exists"> var attachedItem = new GlideRecord("sc_cat_task"); attachedItem.get(items.u_catalog_item); </g2:evaluate> <j2:if test="$[jvar_task_exists]"> <j2:set var="jvar_has_real_tasks" value="true"/> <div> <img src="images/icons/kb_task.gifx" alt="$[HTML:items.u_catalog_item.name]"/> <a class="obvious" href="task.do?sys_id=$[items.task]">$[HTML:items.u_catalog_item.name]</a> </div> </j2:if> <j2:if test="$[!jvar_task_exists]"> <g2:evaluate> items.deleteRecord(); </g2:evaluate> </j2:if> </j2:while> </td> </tr> </j2:if> </j2:if> </j:if> <!-- I don't know what this script is for but it was in my attacked tasks UI Macro (which works) --> <script> /* if ("$[jvar_has_real_tasks]" == "false") { var e = gel("recent_tasks"); if (e) e.style.display = "none"; }*/ </script> </j:jelly>
UI Pages
<!-- list of SDTs to which this article has been attached --> <g:inline template="kb_attached_stds.xml"/> <!-- list of products to which this article pertains --> <g:inline template="kb_affected_products.xml"/> <!-- list of tasks to which this article has been attached --> < g:inline template="kb_attached_tasks.xml"/>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-04-2014 06:21 PM
First off, a word of warning: THIS IS NOT RECOMMENDED AND NOT SUPPORTED. The customizations you've made may very well "break" KB viewing at upgrade time.
The acceptable way to do this is to add a custom UI Macro called "kb_view_custom", in which you can write whatever Jelly you like.
Per your question, you have at least one typo, potentially two, in your UI Page.
- In your text, you have noted your custom UI Macro is named "kb_attached_changes", but that's not referenced in the UI Page.
- Also in the UI Page, you have a comment "list of SDTs to which this article has been attached", whereas the UI Macro referenced is "std" not "sdt".
Not seeing the original macro you copied, I will note that you need to change all of the jvar_ references to unique names.
Finally, to help troubleshooting, add <g:breakpoint /> and <g2:breakpoint /> tags at the top or bottom of your code, to see the variables in scope and their values. Then, turn on the "Debug Logs" module to see the output at the bottom of the page.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-05-2014 07:16 AM
I thought I mentioned in my original question that I was working on my kb_view_custom UI Pages, but I see now that I did not. Thank you for that heads up though and I am using kb_view_custom. I also did make sure the name of the UI Macro matches the one I used in kb_view_custom and that is now kb_attached_changes. I didn't know that you must have different jvar_ variables than other UI Macros. I was using the jvar_ references from the UI Macro I copied from. So I also changed all of those to be unique names.
The script still is not working but I am going to use breakpoint to help me debug. Also in my script logs I am getting the sys_id for the Knowledge article I view, but that could be a different script that is running from a business rule. Thanks for the help!