Jelly Scripting- Getting field values

harshvardhan_11
Giga Expert

What is the way to get the field values in Jelly Scripting.

For example, I want to find the number of tickets of each priority value. How could I loop over each priority value (without passing its values as Array).

5 REPLIES 5

Deepak Ingale1
Mega Sage

Hello Harsh,


You can do it by using g:evaluate tag and then by doing usual gliderecord queries and provide a parameter jelly=true;


To use it in jelly script in 'j' tag, you need to use JEXL expressions.



http://wiki.servicenow.com/index.php?title=Jelly_Tags#evaluate



And everything to know about jelly, refer to wonderful blogs by



SlightlyLoony's Blog


bernyalvarado
Mega Sage

Hi, Harshvardhan Joshi



There's various way of doing that. One way is the way that Deepak describes. Another way may to do it, and also within the <g:evaluate> is to do it through a GlideAggregate



For instance, your GlideAggregate code (assuming you only want the open incidents) by priority could be something like the following:



var count = new GlideAggregate('incident');


count.addQuery('active', 'true');


count.addAggregate('COUNT', 'priority');


count.query();    


while (count.next()) {


    var priority = count.priority;


    var priorityCount = count.getAggregate('COUNT', 'priority');


    gs.log("The are currently " + priorityCount + " incidents with a priority of " + priority);


}



As for the Jelly on itself, follow the simple example on this link and you should be set:


http://servicenowdeveloper.com/2014/05/jelly-example-gliderecord/



Thanks,


Berny


Harshvardhan Joshi Some other and great resources around Jelly are the following:



I use this one all the time --> Extensions to Jelly Syntax - ServiceNow Wiki


http://servicenowdeveloper.com/tag/jelly/



Videos:


TechNow Episode 1 | ServiceNow Jelly Scripting Part 1 of 3 - YouTube


TechNow Episode 2 | ServiceNow Jelly Scripting Part 2 of 3 - YouTube


TechNow Episode 3 | ServiceNow Jelly Scripting Part 3 of 3 - YouTube



and finally, and perhaps one of the most important ones, use current UI macros and UI pages as great examples of what can be done. I do that all the time as well .



I hope all this is helpful!



Thanks,


Berny


bernyalvarado
Mega Sage

Hi Harshvardhan Joshi, were you able to get this resolved?


Would you mind marking the responses as helpful/correct so that we can close this thread?



Please let us know if you need any further help.



Cheers!



Thanks,


Berny