Jelly script prints Array variable as a string. Can someone help?

Ash28
Kilo Contributor

I have an array of errors I received from UI action and trying to print it on a UI page. But Instead of running through whole Array jelly prints all values as a string. 

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
	<g2:evaluate var="jvar_errorlist"  object="true" jelly = 'true'>
		jelly.sysparm_errors;
	</g2:evaluate>
	<j2:forEach var="jvar_error" items="$[jvar_errorlist]">    
			<h4> ERROR: $[jvar_error] </h4>
 	</j2:forEach> 
</j:jelly>

If there is an array like ['This is error 1', 'This is error 2', 'This is error 3', 'This is error 4']. I want it to be like

ERROR: This is error 1

ERROR: This is error 2

ERROR: This is error 3

ERROR: This is error 4

Can someone explain what I'm doing wrong here. I tried many different ways but I can't get it working.

1 ACCEPTED SOLUTION

Hi,

So you are sending the value from UI action

please update as below

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
     
<j2:set var="jvar_errors" value="$[RP.getWindowProperties().get('sysparm_errors')]"/>	 

	<g2:evaluate var="jvar_errorlist" object="true" jelly="true">
		var arr = jelly.jvar_errors;
		arr = arr.toString().split(',');
		arr;
	</g2:evaluate>
	
	<j2:forEach var="jvar_error" items="$[jvar_errorlist]">    
		<h4> ERROR: $[jvar_error] </h4>
 	</j2:forEach> 
	
</j:jelly>

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

8 REPLIES 8

Weird. It's the same as 

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
     
	<g2:evaluate var="jvar_errorlist"  object="true" jelly = 'true'>
		var arr = jelly.sysparm_errors;
		arr;
	</g2:evaluate>
	<j2:forEach var="jvar_error" items="$[jvar_errorlist]">    
		<h4> ERROR: $[jvar_error] </h4>
 	</j2:forEach> 
</j:jelly>

UI Action method from which I'm calling..

function showRebuildError(errorList){
	alert(errorList.length); // This prints 4
	var gm = new GlideModal("x_gmi_build_error_dialog", false, 'modal-lg');
	gm.setTitle("Your request cannot proceed. Please fix below errors!"); 
	gm.setPreference('sysparm_errors',  errorList);
	gm.setWidth(600,300);
	gm.render();
	return false;
}

Hi,

So you are sending the value from UI action

please update as below

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
     
<j2:set var="jvar_errors" value="$[RP.getWindowProperties().get('sysparm_errors')]"/>	 

	<g2:evaluate var="jvar_errorlist" object="true" jelly="true">
		var arr = jelly.jvar_errors;
		arr = arr.toString().split(',');
		arr;
	</g2:evaluate>
	
	<j2:forEach var="jvar_error" items="$[jvar_errorlist]">    
		<h4> ERROR: $[jvar_error] </h4>
 	</j2:forEach> 
	
</j:jelly>

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

That works!!!!

Thanks a ton, Ankur.

You are welcome

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader