How do I get the current record ID via UI Macro for a form formatter?

Fenkins
Kilo Explorer

I am trying to re-write some of the functionality from OOB cmdb relationships formatter, as far as I understand the OOB does not offers source code to the end users, thus, I am working on the custom replacement. So far I am stuck with adding the current sys_id of cmdb_ci record to the query. I have tried various options offered by community and googled extensively, but nothing works so far. Please check the code below:

 

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
 
 <style>
 <style>
table {
 font-family: arial, sans-serif;
 border-collapse: collapse;
 width: 100%;
}

td, th {
 border: 1px solid #dddddd;
 text-align: left;
 padding: 8px;
}

tr:nth-child(even) {
 background-color: #dddddd;
}
</style>
 </style>

<g:evaluate >
 var gr = new GlideRecord("cmdb_rel_ci");
 gr.addQuery("parent",current.sys_id);
 gr.query();

 var glo = {
 name:"check"
 };
</g:evaluate>
 
 
 <table>
 <tr>

 <th>
 Name
 Yo? ${glo.check}
 </th>

 <th>
 sys_id
 </th>

 </tr>

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

 <td>
 <a href="cmdb_ci.do?sys_id=${gr.child.sys_id}">${gr.child.name.getDisplayValue()}</a>
 </td>
 
 <td>
 ${gr.child.sys_id.getDisplayValue()}
 </td>
 
 </tr>

</j:while>
 
 </table>


</j:jelly>

 

The issue I am having in this example is within the current.sys_id. I tried using g_form and screening the current.sys_id with ${} etc etc, but none of it gets the job done. Please advise.

1 REPLY 1

Joseph Gabriel
Tera Contributor

You can use `g2:evaluate` (phase 2 Jelly processing) to access the `current` variable.

 

<g2:evaluate>
    var gr = new GlideRecord("incident");
    gr.addActiveQuery();
    gr.query();
</g2:evaluate>

<h1>Row count: $[gr.getRowCount()]</h1>