GlideAggregate in UI Page

lonesoac01
Giga Guru

Hello all,

 

   I am trying to use the GlideAggregate in a UI Page.  I am trying hard to remove the "getRowCount" of the GlideRecord that I already have functional.  Here is the code of the HTML section of the UI Page:

 

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<g:evaluate>
	// This is where I would perform the gliderecord queries.
	var JSON_thingy = RP.getWindowProperties().get('JSON_thingy');
	var parser = new global.JSON();
	var obj = parser.decode(JSON_thingy);
	obj;
</g:evaluate>

<g:evaluate>
	var notification_sys_id = gs.getProperty('page_change_assignee');
	var sys_notif_subscription_GR = new GlideRecord("sys_notif_subscription");
	// The below encoded query looks for the Assignee's sys_id and Notification sys_id
	//  If it returns a record, then they are subscribed to the notification.
	sys_notif_subscription_GR.addEncodedQuery('user=' + obj.assigned_to_sys_id + '^notification=edf8ebd397a5fd10408a347de053af4b^active=true');
	sys_notif_subscription_GR.query();
	sys_notif_subscription_GR;
</g:evaluate>

<j:if test="${!sys_notif_subscription_GR.hasNext()}">
   The Assignee is not subscribed to the 'Page Change Assignee'
</j:if>
<j:if test="${sys_notif_subscription_GR.next()}">
   The Assignee is subscribed to the 'Page Change Assignee'
</j:if>

<table style="margin:20px 10px;">
	<tr>
		<td>
			<label for="inc_cause"> Page Change Assignee</label>
		</td>
		<td>
			<j:choose>
				<select id="inc_cause">
					<option value="" selected="selected">-- None --</option>
					<option value="${obj.assignment_group_sys_id}">${obj.assignment_group_display}</option>
					<j:when test="${sys_notif_subscription_GR.getRowCount() == 1}">
						<option value="${obj.assigned_to_sys_id}">${obj.assigned_to_display}</option>
					</j:when>
				</select>
			</j:choose>
		</td>
	</tr>
	<tr>
		<td colspan="2" style="text-align:right;padding-top:10px;">
			<button class="btn btn-default" onclick="closeWindow()" style="margin-right:10px;">Cancel</button>
			<button class="btn btn-primary" onclick="update_ticket()">Ok</button>
		</td>
	</tr>
</table>
</j:jelly>
1 ACCEPTED SOLUTION

Sohithanjan G
Kilo Sage
Kilo Sage

Hi @lonesoac01 

  1. Instead of checking sys_notif_subscription_GR.getRowCount(), you can directly check if the sys_notif_subscription_GR.next() returns true.
  2. Use this information inside the <j:choose> block to conditionally add options to the dropdown.

    In this modification, I replaced the <j:when> condition with <j:choose> and <j:when> to directly check if sys_notif_subscription_GR.next() returns true. If it returns true, it means there is a record, and the corresponding option is added to the dropdown.

     

    This should achieve the desired behavior without using getRowCount(). The <j:choose> block allows you to conditionally render different parts of the HTML based on whether a record exists in the GlideRecord.


    This is the updated code:

 

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
  <g:evaluate>
    var JSON_thingy = RP.getWindowProperties().get('JSON_thingy');
    var parser = new global.JSON();
    var obj = parser.decode(JSON_thingy);
    obj;
  </g:evaluate>

  <g:evaluate>
    var notification_sys_id = gs.getProperty('page_change_assignee');
    var sys_notif_subscription_GR = new GlideRecord("sys_notif_subscription");
    sys_notif_subscription_GR.addEncodedQuery('user=' + obj.assigned_to_sys_id + '^notification=edf8ebd397a5fd10408a347de053af4b^active=true');
    sys_notif_subscription_GR.query();
    sys_notif_subscription_GR;
  </g:evaluate>

  <j:choose>
    <select id="inc_cause">
      <option value="" selected="selected">-- None --</option>
      <option value="${obj.assignment_group_sys_id}">${obj.assignment_group_display}</option>
      <j:when test="${sys_notif_subscription_GR.next()}">
        <option value="${obj.assigned_to_sys_id}">${obj.assigned_to_display}</option>
      </j:when>
    </select>
  </j:choose>

  <j:if test="${!sys_notif_subscription_GR.hasNext()}">
    The Assignee is not subscribed to the 'Page Change Assignee'
  </j:if>
  <j:if test="${sys_notif_subscription_GR.hasNext()}">
    The Assignee is subscribed to the 'Page Change Assignee'
  </j:if>

  <table style="margin:20px 10px;">
    <tr>
      <td>
        <label for="inc_cause"> Page Change Assignee</label>
      </td>
      <td>
        <j:choose>
          <select id="inc_cause">
            <option value="" selected="selected">-- None --</option>
            <option value="${obj.assignment_group_sys_id}">${obj.assignment_group_display}</option>
            <j:when test="${sys_notif_subscription_GR.next()}">
              <option value="${obj.assigned_to_sys_id}">${obj.assigned_to_display}</option>
            </j:when>
          </select>
        </j:choose>
      </td>
    </tr>
    <tr>
      <td colspan="2" style="text-align:right;padding-top:10px;">
        <button class="btn btn-default" onclick="closeWindow()" style="margin-right:10px;">Cancel</button>
        <button class="btn btn-primary" onclick="update_ticket()">Ok</button>
      </td>
    </tr>
  </table>
</j:jelly>
​

 


Please mark as accepted & helpful if it suffice your requirement

BR, Sohith

Please mark as Accepted Solution if this solves your query and HIT Helpful if you find my answer helped you. This will help other community mates too..:)

View solution in original post

2 REPLIES 2

Sohithanjan G
Kilo Sage
Kilo Sage

Hi @lonesoac01 

  1. Instead of checking sys_notif_subscription_GR.getRowCount(), you can directly check if the sys_notif_subscription_GR.next() returns true.
  2. Use this information inside the <j:choose> block to conditionally add options to the dropdown.

    In this modification, I replaced the <j:when> condition with <j:choose> and <j:when> to directly check if sys_notif_subscription_GR.next() returns true. If it returns true, it means there is a record, and the corresponding option is added to the dropdown.

     

    This should achieve the desired behavior without using getRowCount(). The <j:choose> block allows you to conditionally render different parts of the HTML based on whether a record exists in the GlideRecord.


    This is the updated code:

 

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
  <g:evaluate>
    var JSON_thingy = RP.getWindowProperties().get('JSON_thingy');
    var parser = new global.JSON();
    var obj = parser.decode(JSON_thingy);
    obj;
  </g:evaluate>

  <g:evaluate>
    var notification_sys_id = gs.getProperty('page_change_assignee');
    var sys_notif_subscription_GR = new GlideRecord("sys_notif_subscription");
    sys_notif_subscription_GR.addEncodedQuery('user=' + obj.assigned_to_sys_id + '^notification=edf8ebd397a5fd10408a347de053af4b^active=true');
    sys_notif_subscription_GR.query();
    sys_notif_subscription_GR;
  </g:evaluate>

  <j:choose>
    <select id="inc_cause">
      <option value="" selected="selected">-- None --</option>
      <option value="${obj.assignment_group_sys_id}">${obj.assignment_group_display}</option>
      <j:when test="${sys_notif_subscription_GR.next()}">
        <option value="${obj.assigned_to_sys_id}">${obj.assigned_to_display}</option>
      </j:when>
    </select>
  </j:choose>

  <j:if test="${!sys_notif_subscription_GR.hasNext()}">
    The Assignee is not subscribed to the 'Page Change Assignee'
  </j:if>
  <j:if test="${sys_notif_subscription_GR.hasNext()}">
    The Assignee is subscribed to the 'Page Change Assignee'
  </j:if>

  <table style="margin:20px 10px;">
    <tr>
      <td>
        <label for="inc_cause"> Page Change Assignee</label>
      </td>
      <td>
        <j:choose>
          <select id="inc_cause">
            <option value="" selected="selected">-- None --</option>
            <option value="${obj.assignment_group_sys_id}">${obj.assignment_group_display}</option>
            <j:when test="${sys_notif_subscription_GR.next()}">
              <option value="${obj.assigned_to_sys_id}">${obj.assigned_to_display}</option>
            </j:when>
          </select>
        </j:choose>
      </td>
    </tr>
    <tr>
      <td colspan="2" style="text-align:right;padding-top:10px;">
        <button class="btn btn-default" onclick="closeWindow()" style="margin-right:10px;">Cancel</button>
        <button class="btn btn-primary" onclick="update_ticket()">Ok</button>
      </td>
    </tr>
  </table>
</j:jelly>
​

 


Please mark as accepted & helpful if it suffice your requirement

BR, Sohith

Please mark as Accepted Solution if this solves your query and HIT Helpful if you find my answer helped you. This will help other community mates too..:)

yeah!  Your solution was what I needed!  Thank you!  I had to make a minor adjustment to what you suggested, but no biggie.  The below is my final adjustment.

 

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
  <g:evaluate>
    var JSON_thingy = RP.getWindowProperties().get('JSON_thingy');
    var parser = new global.JSON();
    var obj = parser.decode(JSON_thingy);
    obj;
  </g:evaluate>

  <g:evaluate>
    var notification_sys_id = gs.getProperty('page_change_assignee');
    var sys_notif_subscription_GR = new GlideRecord("sys_notif_subscription");
    sys_notif_subscription_GR.addEncodedQuery('user=' + obj.assigned_to_sys_id + '^notification=edf8ebd397a5fd10408a347de053af4b^active=true');
    sys_notif_subscription_GR.query();
    sys_notif_subscription_GR;
  </g:evaluate>

  <j:if test="${!sys_notif_subscription_GR.hasNext()}">
    The Assignee is not subscribed to the 'Page Change Assignee'
  </j:if>
  <j:if test="${sys_notif_subscription_GR.hasNext()}">
    The Assignee is subscribed to the 'Page Change Assignee'
  </j:if>

  <table style="margin:20px 10px;">
    <tr>
      <td>
        <label for="inc_cause"> Page Change Assignee</label>
      </td>
      <td>
	  	<j:choose>
			<select id="inc_cause">
				<option value="${obj.assignment_group_sys_id}">${obj.assignment_group_display}</option>
				<j:when test="${sys_notif_subscription_GR.next()}">
					<option value="${obj.assigned_to_sys_id}">${obj.assigned_to_display}</option>
				</j:when>
    		</select>
  		</j:choose>
      </td>
    </tr>
    <tr>
      <td colspan="2" style="text-align:right;padding-top:10px;">
        <button class="btn btn-default" onclick="closeWindow()" style="margin-right:10px;">Cancel</button>
        <button class="btn btn-primary" onclick="update_ticket()">Ok</button>
      </td>
    </tr>
  </table>
</j:jelly>