
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-17-2016 03:47 AM
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-17-2016 10:58 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-17-2016 04:02 AM
You have to use jelly tags. Go through Jelly Tags - ServiceNow Wiki
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-17-2016 04:05 AM
Also check General Scripting - ServiceNow Wiki for more.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-17-2016 05:01 AM
Thanks for your reply , i tried the script using <g:evaluate> tags , but i want to write the code as above which i have tried in background script
i am not getting here how to use glide record two times , kindly help
----------------------------------------------------------------------------------
<g:evaluate>
var user_obj=new GlideRecord("sys_user");
user_obj.addQuery('sys_id',gs.getUserID());
user_obj.query();
</g:evaluate>
<j:if test="${user_obj.next()}">
Dear ${user_obj.email}
</j:if>
<g:evaluate var="jvar_ivi_user_details" object="true" >
var ivi_user_details = new GlideRecord('x_eyfso_it_capabil_itca_user');
ivi_user_details.addQuery('respondent_email_id', ${user_obj.email}); // how to get here the value i want here email id from sys_user table//
ivi_user_details.query();
</g:evaluate>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-17-2016 10:58 AM
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