- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-29-2014 09:23 AM
I am very new to Jelly. I am trying to add some text to the kb_article_header. I want to add the approver of that Knowledge article, but not every article will have an approver. This is where I am getting stuck. I only want to show "Approver:" when there is an approver. Right now this is my script and I have tried many different things but the debugger and logs say that it "cannot convert null to an object". Does anybody have any suggestions for what I can change?
<g:evaluate var="jvar_gr" object="true">
var gr = new GlideRecord("kb_knowledge");
gr.addQuery("sys_id", current.sys_id);
gr.addQuery("u_mop_approver", "!=", '');
gr.query();
gr;
</g:evaluate>
<j:if test="${jvar_gr.next()}">
<span style="font-weight:bold;padding-left:8px;color:#000000;font-size:14px;">${gs.getMessage("Approver")}:</span><span style="color:#000000;font-size:12px;">$[SP]$[JS,HTML:kb.u_mop_approver.getDisplayValue()]</span>
</j:if>
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-29-2014 02:50 PM
Well that is strange. I guess we will have to stick with the !=:
<j2:if test="$[kb.u_mop_approver != '']">
<span style="font-weight:bold;padding-left:8px;color:#000000;font-size:14px;">${gs.getMessage("Approver")}:</span>
<span style="color:#000000;font-size:12px;">$[SP]$[JS,HTML:kb.u_mop_approver.getDisplayValue()]</span>
</j2:if>
I tested a version of this in my instance and it worked.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-29-2014 09:44 AM
HI Angela, on the line:
<j:if test="${jvar_gr.next()}">
Try using:
<j:if test="${jvar_gr.hasNext()}">
Other than that, I see you have the line at the bottom:
kb.u_mop_approver.getDisplayValue()
Of course, I can't see if "kb" has been defined or not, but shouldn't it be:
jvar_gr.u_mop_approver.getDisplayValue()
Let me know if this helps, cheers.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-29-2014 09:51 AM
Sorry I should have included that but yes "kb" has been defined earlier in the script. I tried .hasNext() but it still is getting stuck at the line "gr.addQuery("sys_id", current.sys_id);" and says "Cannot convert null to an object".
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-29-2014 12:05 PM
Hi Angela,
I am a little confused. To what does "current" refer. I am pretty certain that is the problem. You are calling a property "sys_id" on an object "current" that does not exist.
I believe what you are looking to do is test the kb_article record passed into the UI Macro for a non-empty u_mop_approver. For this, you do not need an additional query. The variable "kb" already holds the GlideRecord that you require. For example:
<j:if test="${kb.u_mop_approver != ''}">
<span style="font-weight:bold;padding-left:8px;color:#000000;font-size:14px;">${gs.getMessage("Approver")}:</span>
<span style="color:#000000;font-size:12px;">$[SP]$[JS,HTML:kb.u_mop_approver.getDisplayValue()]</span>
</j:if>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-29-2014 01:42 PM
Travis,
I think you are correct and that current is my issue. I am used to being able to use current to refer to the article or page I am currently on. I am trying to use current to see if the current article is on has an approver. However the more time I spend researching Jelly I am coming to the conclusion that that is not how Jelly works.
Then "kb". "kb" is defined as the GlideRecord but it only works in the javascript part. It would be convenient if "kb" would work for either g or j but it does not seem too. Again I am very new to Jelly and I have tried to look up tutorials but I can't seem to find what I am looking for.
I tried your example and messing around with your example but it still didn't work.