Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

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 Lundqvist



Thanks for your reply


No problem 😃 Just keep asking if you have any probs.



//Göran


Ivano B
ServiceNow Employee
ServiceNow Employee

Hi Akhil


As explained at point 7.2 in the wiki (Extensions to Jelly Syntax - ServiceNow Wiki ) you need to use the attribute jelly = true.


Try and let me know if this works.



<g:evaluate var="value" object="true" jelly="true">


  var value = new GlideRecord("sys_user");


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


  value.query();


  value;


</g:evaluate>



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


      Email is :${value.getValue('email')};


      <g:evaluate var="user" object="true" jelly="true">


          var mail = jelly.value.getValue('email');


          var user = new GlideRecord('x_eyfso_it_capabil_itca_user');;


          user.addQuery('respondent_email_id', mail);


          user.query();


          user;


        </g:evaluate>


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


              Dear ${user.getValue('respondent_name')};


        </j:while>


</j:while>


It worked I have modified the script before , anyhow thanks for your reply


is there any documentation other than wiki available to learn more about jelly scripting?


You code above give some strange vibs there Ivano,



* You should only use jelly="true" if you are using jelly variables instead a <g:evaluate>. so in your first evaluate there is no reason for it.



*   In your second <g:evaluate> you are calling for a jelly variable(jelly.value). Always begin the variable name of jelly variables with jvar_ Otherwise the Jelly master will go crazy. Which probably means that in your first <g:evaluate> will have value="jvar_value" instead.



Last thing. Remember that you can pass jelly variables inside a <g:evaluate> but it passes a copy into it what ever happens inside the <g> doesn't affect the jvar_



Hope I don't sound to stiff , just want to help so you can avoid strange errors in the future.



//Göran