Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

UI Page popup from KBA edit page doesn't respond to any jelly code

jeremyduffy
Kilo Guru

On the KBA edit page, I have a UI action with the following:

 

function openAttestationWindow() {
	var dialog = new GlideDialogWindow("attestation_window");
	dialog.setWidth(400);
	dialog.setTitle("Article Attestation");
	dialog.setPreference("sysparm_sys_id", g_form.getUniqueValue()); // Pass sysparm_sys_id correctly
	dialog.setPreference("resizable", true);
	dialog.render();
}

 

This correctly opens my UI page where I have script that prints some HTML, but none of the control code seems to work. Even something as simple as this:

 

<g:evaluate var="kbSysId" expression="sysparm_sys_id ? sysparm_sys_id : 'No sys_id found'"/> 
<g:out var="kbSysId"/> 

This should print SOMETHING, but prints nothing. I have it sandwiched between text so I know that the text is working, but the jelly code is just ignored. Same for this:

<g:evaluate var="articleOwnerStatus" expression="current.article_owner ? 'Complete' : 'Incomplete'"/>

<li style="color: ${articleOwnerStatus == 'Complete' ? 'green' : 'orange'};">${articleOwnerStatus == 'Complete' ? '✔' : '✘'} Has an Article Owner (Dept) value</li>

I get the LI bullet with text, but no color and no check/x. What is going on?

1 ACCEPTED SOLUTION

jeremyduffy
Kilo Guru

Apparently g:out does not work for unknown reasons, but I was able to finally get this working using the following:

	<g:evaluate var="kbRecord" jelly="true" object="true">
		var kbRecordGr = new GlideRecord("kb_knowledge");
		kbRecordGr.get(RP.getParameterValue("sysparm_sys_id"));
		kbRecordGr;
	</g:evaluate>
	${kbRecordGr.short_description}<br/>
	${kbRecordGr.cmdb_ci.name}<br/>
	${kbRecordGr.u_article_owner.name}<br/>


	<j:if test="${kbRecordGr.flagged}">
		<p>flagged</p>
	</j:if>
	<j:if test="${!kbRecordGr.flagged}">
		<p>Noteflagged</p>
	</j:if>

The first thing is that I needed to do a direct glide lookup with the sys_id passed from before. Then I can just check the values, but for NO REASON, I have to use the kbRecordGr value from the evaluate and not kbRecord itself. It's incredibly weird, but it finally works.

View solution in original post

6 REPLIES 6

Okay, can you please try this:

<?xml version="1.0" encoding="utf-8"?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide">
  <div style="padding: 10px;">
    <h3>Article Attestation</h3>
    
    <!-- Test if Jelly is working -->
    <div style="color: gray; font-size: 0.9em;">
      <g:out> Jelly Engine Active</g:out>
    </div>

    <!-- Display KB Article Sys ID -->
    <div>
      <strong>Article Sys ID:</strong> 
      <g:evaluate var="kbSysId" expression="sysparm_sys_id ? sysparm_sys_id : 'No sys_id provided'"/>
      <g:out var="kbSysId"/>
    </div>

    <!-- Fetch KB Article Record -->
    <g:evaluate var="current" expression="new GlideRecord('kb_knowledge').get('${sysparm_sys_id}')"/>

    <!-- Display Article Owner Status (no colors) -->
    <div>
      <strong>Article Ownership Status:</strong> 
      <g:choose>
        <g:when test="${current.article_owner}">
          ✓ 
          <em>${current.article_owner.getDisplayValue()}</em>
        </g:when>
        <g:otherwise>
          ✗ 
          No article owner assigned
        </g:otherwise>
      </g:choose>
    </div>

    <!-- Add spacing for readability -->
    <hr style="border: none; height: 20px;">
  </div>
</j:jelly>

jeremyduffy
Kilo Guru

Apparently g:out does not work for unknown reasons, but I was able to finally get this working using the following:

	<g:evaluate var="kbRecord" jelly="true" object="true">
		var kbRecordGr = new GlideRecord("kb_knowledge");
		kbRecordGr.get(RP.getParameterValue("sysparm_sys_id"));
		kbRecordGr;
	</g:evaluate>
	${kbRecordGr.short_description}<br/>
	${kbRecordGr.cmdb_ci.name}<br/>
	${kbRecordGr.u_article_owner.name}<br/>


	<j:if test="${kbRecordGr.flagged}">
		<p>flagged</p>
	</j:if>
	<j:if test="${!kbRecordGr.flagged}">
		<p>Noteflagged</p>
	</j:if>

The first thing is that I needed to do a direct glide lookup with the sys_id passed from before. Then I can just check the values, but for NO REASON, I have to use the kbRecordGr value from the evaluate and not kbRecord itself. It's incredibly weird, but it finally works.