- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on 10-16-2018 06:26 AM
Introduction:
It not a secret that there is lack of documentation regarding “Jelly” used in ServiceNow Platform. And when we are talking about a developing process, of course, this situation may be a cause of numerous difficulties and misunderstandings.
To make developer’s life a bit more easily the ScienceSoft conducted an investigation. As a result concept solution has been developed which allows to obtain properties and methods (API, if you will) stored in available global objects (or their prototypes).
Description:
The idea is simple. The code traversals an object, defines its properties and sets them to an array. After that the received data (name, description and type) are displayed in a table. If it is necessary it is easy to expand this functionality to obtain other data.
To beautify slightly the displayed result there were added a “twitter bootstrap” library and a simple counter for table’s rows was implemented.
Please, take a look at the row on the UI-Page containing extractProperties() function. Here you are able to pass a necessary object as a function argument to retrieve the object’s API. For instance, it might be “global”, “RP”, “ListProperties” (after the appropriate table injection) or any other available object.
Conclusion:
Described concept solution has been revealed for development purposes only and might be used for generation of API-like documentation if needed. At the same time it might be useful for learning the “Jelly” abilities and the ServiceNow Platform in general.
Good luck in your future experiments 😉
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<!-- inject bootstrap for styling -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<style>
.main-content {
max-width:1250px;
}
</style>
<!-- Note: additional global properties appear after table injection (e.g. ListProperties)
Example of "incident" table injection:
<g:list_default table="incident"/>
-->
<g:evaluate var="jvar_count" object="true">
({
currentValue: 0,
get val() {
this.currentValue++;
return '' + this.currentValue;
}
})
</g:evaluate>
<g:evaluate var="jvar_obj" object="true">
function extractProperties(global) {
var res = [];
for(var prop in global) {
try {
res.push({
name: prop,
description: global[prop],
type: typeof global[prop]
});
}
catch(err) {
res.push({
name: prop,
description: 'ERROR: '+ err,
type: ''
});
}
};
res.sort(function(firstElement, secondElement){
if (firstElement.type === secondElement.type) {
return firstElement.name.localeCompare(secondElement.name);
}
return secondElement.type.localeCompare(firstElement.type);
});
return res;
}
extractProperties(global);
</g:evaluate>
<main class = "container-fluid main-content">
<div class = "row">
<div class = "col-md-12">
<h2 class = "text-center">Object's API</h2>
<table class="table table-hover table-striped table-bordered">
<thead class="success">
<tr>
<th>№</th>
<th>Property name</th>
<th>type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<j:forEach var="jvar_method" items="${jvar_obj}">
<tr>
<th>${SAFE:jvar_count.val}</th>
<td>${SAFE:jvar_method.name}</td>
<td>${SAFE:jvar_method.type}</td>
<td>${SAFE:jvar_method.description}</td>
</tr>
</j:forEach>
</tbody>
</table>
</div>
</div>
</main>
</j:jelly>
Some results for the “global” and “RP” objects are shown below. Here you are able to see names of stored objects and methods and some description (the result of overriding the native “toString()” method at the Platform level).
Pic.1 extracted APIs for variable: global
Pic.2 extracted APIs for variable: RP
Pic.3 extracted APIs for variable: ListProperties
- 1,943 Views