The CreatorCon Call for Content is officially open! Get started here.

Jelly Scripting

Akhil Kumar1
Mega Sage

Hi All ,

I am trying to do some code in CMS pages using Jelly Script , i have created a script and run in background script and it's working fine

but i am not getting how to write the same code in Jelly Script , please find the below script which i have wrote in background script

---------------------

var user_obj=new GlideRecord("sys_user");

user_obj.addQuery('sys_id',gs.getUserID());

user_obj.query();

if(user_obj.next())

{

gs.print("hello::"+user_obj.email);

var ivi_user_details = new GlideRecord('x_eyfso_it_capabil_itca_user');

ivi_user_details.addQuery('respondent_email_id',user_obj.email);

ivi_user_details.query();

if(ivi_user_details.next())

{

gs.print("hello::"+ivi_user_details.respondent_name);

}

}

________________________________________________________

Kindly help and also please give some inputs to learn more about Jelly Scripting

1 ACCEPTED SOLUTION

I took a bit of your script and this is how you can make it. Hopefully I'm good enough to explain so you understand how to use it.



<?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_gr" object="true">


        var gr = new GlideRecord("sys_user");


  gr.addQuery('sys_id',gs.getUserID());


    gr.query();


    gr;


</g:evaluate>



<j:while test="${jvar_gr.next()}">


dear   ${jvar_gr.getValue('email')}


</j:while>    


</j:jelly>



I learned my first jelly things while looking at the TechNows jelly episodes. You can find the first one here: TechNow Episode 1 | ServiceNow Jelly Scripting Part 1 of 3 - YouTube




If you want to use jelly variables you need 2 things.



1. Put jelly="true" in the evaluate like this:



<g:evaluate jelly="true">



2. when you refer to a jelly variable in the evaluate you need to put jelly. before the variable name like this:



var users_email = jelly.jvar_this_is_the_jelly_variablename



if you got any other questions, feel free to ask



//Göran


View solution in original post

14 REPLIES 14

Hi Goran



You're absolutely right. Apologies for the mistakes.


About the first "jelly=true" I didn't notice realise was there  


About the use of variable names...


I worked directly on the code provided by Akhil instead of providing a real final solution as you did in your answer...that i noticed only now.


Ivano B
ServiceNow Employee
ServiceNow Employee

Probably the best way of learning Jelly is using the existing UI pages/UI Macros available in the system.


You can try to analyse their structure and and the code, comparing the actual behaviours of the pages with the explanations provided by the wiki.



Cheers


Ivano


Thank you Ivano Bergamaschi and Goran Lundqvist for wonderful help and support


Appreciate it



No problem, just keep firing away those questions 😎 happy to help.



//Göran


Can you provide some inferences on this? @Göran WitchDoctor Lundqvist 

https://community.servicenow.com/community?id=community_question&sys_id=8fe86402dbe9c110dd886c8e13961994