If condition in jelly script

Hafsa1
Mega Sage

<j:if test="${gs.getUserID()==current.assigned_to}">

I want to put if condition in macro to compare "if logged in user matches assigned to" like above. What will be the correct code if it.

1 ACCEPTED SOLUTION

Harsh Vardhan
Giga Patron

<g:evaluate var="jvar_value" jelly="true">

 

var show = 'false';

if(gs.getUserID()== current.assigned_to){

show = 'true';

}

show;

</g:evaluate>

 

 you can now use jvar_value variable to compare in if statement and show some html tag

 

 

<j:if test="${jvar_value == 'true'}">

 

<p>This paragraph will be shown when show is true</p>

 

</j:if>

View solution in original post

4 REPLIES 4

Harsh Vardhan
Giga Patron

<g:evaluate var="jvar_value" jelly="true">

 

var show = 'false';

if(gs.getUserID()== current.assigned_to){

show = 'true';

}

show;

</g:evaluate>

 

 you can now use jvar_value variable to compare in if statement and show some html tag

 

 

<j:if test="${jvar_value == 'true'}">

 

<p>This paragraph will be shown when show is true</p>

 

</j:if>

I do not know Jelly at all and I could really use some help.  I only want to show the icon if it finds a record in my table otherwise I don't want to show the icon.  I tried using an example of your jelly if but it doesn't show anything ever, it seems to always come as false.  Can you please look at my code and tell me if I missed something or if there is a way for me to log to see if it's even reading my glide 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="jvar_value" jelly="true">

var show = 'false';
var csysid = current.getUniqueValue();
var cscaseGR = new GlideRecord('u_c_signal');
cscaseGR.addQuery('u_case',csysid);
cscaseGR.addEncodedQuery('u_case.state!=3');
cscaseGR.query();
	if(cscaseGR.next()) {
	show = 'true';
	var cscontact = cscaseGR.u_c_signal_contact;
		}
	show;

	</g:evaluate>
	
	<j:if test="${jvar_value == 'true'}">
	
	<j:set var="jvar_n" value="csignalcontact_url_${ref}"/>
	<span id="${jvar_n}" onclick="csignalcontact_url('${ref}')" title="${gs.getMessage('C-Signal Contact (RSI-VPN)')}" alt="${gs.getMessage('C-Signal Contact(RSI-VPN)')}" tabindex="0" class ="btn btn-default icon-user" style="color:$[cscontact];background-color:#FFFFFF"></span>
	</j:if>	
		<span class="sr-only">CSignalCase</span>

	<script>
		function csignalcontact_url(reference) {
		var cssysid = g_form.getUniqueValue();
		<!--	var csuser = ${gs.getUserID()}; -->
		var csuser = g_user.userID;
		var url = "http://lvd-gsd-rmp-01/amsi/ServiceNowIntegration/viewCase/" + cssysid + "/contact/" +csuser ; 
		window.open(url);
		}
	</script>


</j:jelly>

Thank you,

Stacy

You aren't able to access the "current" variable in "g" scope...needs to be "g2", as in

<g2:evaluate var="jvar_value" jelly="true">

hi @Harsh Vardhan - We are trying to achieve pagination through Jelly script is it possible.

its for a custom widget created to display the affected CI in the CI dashboard.

I followed your blog Custom Widget to show related record on Dashboard
it worked perfect, but now the question is can we control it and show rows per page.

 

Regards,

Kalpana