The Zurich release has arrived! Interested in new features and functionalities? Click here for more

How to access the current object (record) in UI macro jelly script ?

Nilesh Wahule
Tera Guru

Hi There,

 

Happy new year to you !!

 

In this new year, I am exploring few new things and got stuck at one place not sure if it can be achieved or not. Performs some alternative can be there.

 

All I want to do is access the current object in the UI macro when its added to the field so that I can set the sys_id in one of the variable using below syntax and use it in few of the if conditions to render HTML.

 

<g:set var="jvar_sys_id" value="${current.sys_id}"/>

 

But unfortunately, its not working and showing value as NULL.

Could you please suggest some alternate solution for same?

 

Notes:

1. I am aware that we can use the sys_id in the script tags, but as per another community post I can't render script data back to the UI macro jelly scripts, as it renders first.

2. I know about the ${ref} which returns only the reference of table and field on which UI macro is called but not the sys_id or any unique identifier for the record.

 

 

1 ACCEPTED SOLUTION

Michael Jones -
Giga Sage

It's been a while, but, I believe you can only reference current when using "phase 2" so g2. 

Below is a really simple example - you can add this as a formatter to any form view and it will show the sys_id of the current record.  

 

 

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
	<g2:evaluate var='jvar_sys_id'>
          var val = current.getValue('sys_id');
          val;
</g2:evaluate>
	<p>sys_id= $[jvar_sys_id]</p>

</j:jelly>

 

I hope this helps!
Michael D. Jones
Proud member of the GlideFast Consulting Team!

View solution in original post

3 REPLIES 3

Michael Jones -
Giga Sage

It's been a while, but, I believe you can only reference current when using "phase 2" so g2. 

Below is a really simple example - you can add this as a formatter to any form view and it will show the sys_id of the current record.  

 

 

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
	<g2:evaluate var='jvar_sys_id'>
          var val = current.getValue('sys_id');
          val;
</g2:evaluate>
	<p>sys_id= $[jvar_sys_id]</p>

</j:jelly>

 

I hope this helps!
Michael D. Jones
Proud member of the GlideFast Consulting Team!

@Michael Jones -  Thank you very much for this solution. I was going through a lot of articles since last week, but didn't get anything. After changing to phase 2 ( g2) it worked like a charm. Thank you very much. 

If possible, could you please share the detailed jelly scripting handbook for ServiceNow or any course for learning.

I'll admit that most of what I learned was through trial, error, and picking apart a lot of the UI pages that come out of the box. Most of it is just javascript and html. I do recall some great videos that Chuck Tomasi had put out there that helped me get started:

There are 3 of vids - this is a link to the first one (which has links to the other two) - they are a bit old, but the technology (Jelly) hasn't changed so --- still applicable! 

https://www.servicenow.com/community/developer-blog/technow-ep-1-servicenow-jelly-scripting-part-1-o... 

I use these as references for the (more and more rare) instances where I need to brush up (well, that is to say I search for these on Docs as the current version changes, but something like these have been around for sometime). 

https://docs.servicenow.com/bundle/vancouver-application-development/page/script/general-scripting/r... 

https://docs.servicenow.com/bundle/vancouver-application-development/page/script/general-scripting/c... 

 

I hope this helps!
Michael D. Jones
Proud member of the GlideFast Consulting Team!