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.

Dynamic Content Block display unwanted code before intended element

SyncWizard
Tera Contributor

Hi Everyone,

I am building a Dynamic Content Block that retrieves a unique array of short descriptions from a list of records, and then adds those as options for a "ui_choice_input_field" UI Macro.

 

This works, however there is a long line of script displayed before the actual element and I don't understand where it's coming from.

 

I attached a screenshot of the issue.

 

This is my 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 options = [];

		<!-- Get all the demand tasks assigned to this group -->
		var dmnTaskGR = new GlideRecordSecure("dmn_demand_task");
		dmnTaskGR.addQuery("assignment_group","cc4909c41b92edd019f6740f8b4bcbd1");
		dmnTaskGR.query();
		
		<!-- Get a unique list of short descriptions from these demand tasks -->
		while(dmnTaskGR.next()) {
			var shortDesc = dmnTaskGR.getValue("short_description");
			if(!(options.indexOf(shortDesc) >= 0)) {
				options.push(shortDesc);
			}
		}
	</g:evaluate>

	<g:ui_choice_input_field id="shortDescInput" name="shortDescInput" label="Short description:">
		<option value="none">--None--</option>

		<!-- Create an option value for each unique short description value -->
		<j:forEach var="jvar_options" items="${options}">     
			<option value="optVal">${jvar_options}</option>
		</j:forEach>
	</g:ui_choice_input_field>

</j:jelly>

 

This is the code that the dynamic content block displays:

 

var accessibleTooltips = (gs.getPreference('glide.ui.accessibility.accessible.tooltips', 'true') == 'true'); 
accessibleTooltips;
var accessibleDateFormat = (gs.getPreference('glide.ui.accessibility.accessible.dateFormat', 'false') == 'true');
accessibleDateFormat;
var labelTitle = jelly.jvar_element_hint;
var buttonStyle = "display: none;";

if (labelTitle) { 
    if (labelTitle.length > 0) { 
        buttonStyle="";
    }
}

buttonStyle;

var labelTitle = jelly.jvar_element_hint;
var ariaHidden = "true";
if (labelTitle) {
    if (labelTitle.length > 0) {
        ariaHidden="false";
    }
}
ariaHidden;

if (typeof(__ref__) == 'undefined') {
    var __ref__ = null;
    var __ref_string__ = '';
}

 

 

Thanks in advance

1 ACCEPTED SOLUTION

AnveshKumar M
Tera Sage
Tera Sage

Hi @SyncWizard ,

 

Try this 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 options = [];

		<!-- Get all the demand tasks assigned to this group -->
		var dmnTaskGR = new GlideRecordSecure("dmn_demand_task");
		dmnTaskGR.addQuery("assignment_group","cc4909c41b92edd019f6740f8b4bcbd1");
		dmnTaskGR.query();
		
		<!-- Get a unique list of short descriptions from these demand tasks -->
		while(dmnTaskGR.next()) {
			var shortDesc = dmnTaskGR.getValue("short_description");
			if(!(options.indexOf(shortDesc) >= 0)) {
				options.push(shortDesc);
			}
		}
	</g:evaluate>
	<select aria-required="false" aria-labelledby="Short description:" name="shortDescInput" id="shortDescInput" style="; " class="form-control">
		<option value="none">--None--</option>

		<!-- Create an option value for each unique short description value -->
		<j:forEach var="jvar_options" items="${options}">     
			<option value="optVal">${jvar_options}</option>
		</j:forEach>
	</select>
</j:jelly>

 

Please mark my answer helpful/accept as solution if it helped you 👍✔️

 

Thanks,
Anvesh

View solution in original post

3 REPLIES 3

AnveshKumar M
Tera Sage
Tera Sage

Hi @SyncWizard ,

 

Try this 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 options = [];

		<!-- Get all the demand tasks assigned to this group -->
		var dmnTaskGR = new GlideRecordSecure("dmn_demand_task");
		dmnTaskGR.addQuery("assignment_group","cc4909c41b92edd019f6740f8b4bcbd1");
		dmnTaskGR.query();
		
		<!-- Get a unique list of short descriptions from these demand tasks -->
		while(dmnTaskGR.next()) {
			var shortDesc = dmnTaskGR.getValue("short_description");
			if(!(options.indexOf(shortDesc) >= 0)) {
				options.push(shortDesc);
			}
		}
	</g:evaluate>
	<select aria-required="false" aria-labelledby="Short description:" name="shortDescInput" id="shortDescInput" style="; " class="form-control">
		<option value="none">--None--</option>

		<!-- Create an option value for each unique short description value -->
		<j:forEach var="jvar_options" items="${options}">     
			<option value="optVal">${jvar_options}</option>
		</j:forEach>
	</select>
</j:jelly>

 

Please mark my answer helpful/accept as solution if it helped you 👍✔️

 

Thanks,
Anvesh

Hi @AnveshKumar M ,

 

Can you please pinpoint what exactly is causing this issue when using the OOB "ui_choice_input_field" UI Macro?

 

 

I am very curious of the actual reason causing this issue.


This is the code of the OOB Macro:

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="true" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null">
   <g:macro name="REQUIRED" label="REQUIRED" value="" onchange="onChange('${jvar_name}');" onclick_label="" mandatory="false"/>
   <table class="wide">
     <tr>
       <td id="label.${jvar_name}" class="label" nowrap="true" type="string" choice="0" oncontextmenu="${jvar_oncontextmenu}">
         <g:form_label onclick="${jvar_onclick_label}" for="${jvar_name}"> ${jvar_label}<j2:if test="$[GlideMobileExtensions.getDeviceType() != 'doctype']">:</j2:if></g:form_label>
       </td>
       <td nowrap="true" style="width:100%">
	<select name="${jvar_name}" id="${jvar_name}" onChange="${jvar_onchange}">
		<!-- xml for element type inserted here... -->
		<g:insert/>
	</select>
       </td>
      </tr>
    </table>
</j:jelly>

 

Thanks in advance!

Hi @SyncWizard 

 

ui_choice_input_field contains both Phase1 and Phase 2 jelly tags (g and j are phase 1 tags & g2 and j2 are Phase2 tags), to make it work in content blocks you need to check the Two Phase field as shown in below screenshot.

 

AnveshKumarM_0-1695179526370.png

 

Please mark my answer helpful/accept as solution if it helped you 👍✔️

 

Thanks,
Anvesh