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

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

this should print

<?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 = ['This is error 1','This is error 2','This is error 3','This is error 4'];
		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

Hi Ankur, 

That didn't work. It's still printing 'This is error 1,This is error 2',This is error 3,This is error 4'.. 

Also, I'm getting this array from UI Action parameters so I have to use

var arr =  jelly.sysparm_errors
arr;

Am I right?

Hi,

it worked for me

find_real_file.png

find_real_file.png

Regards
Ankur

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

Hi,

please share your script

Regards
Ankur

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