Jelly script not working in onclick function

Jake Sadler
Kilo Sage

I have created the below script for a dynamic content block on a dashboard and I'm trying to run jelly inside my javascript onclick function.

Can anyone explain why this is not working?

 

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">


<html>

<form id="timeLeft">



Hours: <input type="number" min="0" max="23" id="hours" onChange="validateHours(this.value)"/><br></br>
Minutes: <input type="number" min="0" max="59" id="minutes" onChange="validateMinutes(this.value)"/><br></br>


<input type="button" onclick="myFunction()" value="Submit">
</input>
</form>


<script>
function myFunction() {
var h = document.getElementById("hours").value;
var m = document.getElementById("minutes").value;
alert(h + ' ' + m)
<g:evaluate var="jvar_gr" object="true">
var gd = new GlideDate();
var gr = new GlideRecord('u_engineer_time_left');
gr.addQuery('u_date',gd);
gr.orderByDesc('u_time_left');
gr.query();
gr;
<j:if test="${jvar_gr.next()}">

User with the most time available today is: ${jvar_gr.getDisplayValue('u_user')} with ${jvar_gr.getDisplayValue('u_time_left')} remaining.



</j:if>

</g:evaluate>

}

</script>





</html>

</j:jelly>

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

Do this

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">


	<html>

		<form id="timeLeft">
			Hours: <input type="number" min="0" max="23" id="hours" onChange="validateHours(this.value)"/><br></br>
			Minutes: <input type="number" min="0" max="59" id="minutes" onChange="validateMinutes(this.value)"/><br></br>
			<input type="button" onclick="myFunction()" value="Submit">
			</input>
		</form>

		<p id="message" style="display:none;"></p>

		<script>
			function myFunction() {
			var h = document.getElementById("hours").value;
			var m = document.getElementById("minutes").value;
			// use GlideAjax here and query your table and pass the hours minutes and return the message from script include

			if(returnedMessage != ''){
			document.getElementById("message").innerHTML = returnedMessage;
			}				
			}
		</script>

	</html>

</j:jelly>

Regards
Ankur

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

View solution in original post

3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

within script tag why are you using g:evaluate?

it won't work

Regards
Ankur

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

Hi,

 

I'm trying to run a query when the button is clicked. I'm not very experienced with jelly. H Would I do a normal GlideRecord or would I need to restructure my code? 

 

 

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

Do this

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">


	<html>

		<form id="timeLeft">
			Hours: <input type="number" min="0" max="23" id="hours" onChange="validateHours(this.value)"/><br></br>
			Minutes: <input type="number" min="0" max="59" id="minutes" onChange="validateMinutes(this.value)"/><br></br>
			<input type="button" onclick="myFunction()" value="Submit">
			</input>
		</form>

		<p id="message" style="display:none;"></p>

		<script>
			function myFunction() {
			var h = document.getElementById("hours").value;
			var m = document.getElementById("minutes").value;
			// use GlideAjax here and query your table and pass the hours minutes and return the message from script include

			if(returnedMessage != ''){
			document.getElementById("message").innerHTML = returnedMessage;
			}				
			}
		</script>

	</html>

</j:jelly>

Regards
Ankur

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