- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2024 12:22 AM - edited 01-23-2024 12:37 AM
Hi @Ankur Bawiskar ,
Could please help me in the below script.
Ui action script:
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2024 03:28 AM
got it
try this
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<h3>Event table</h3>
<g:evaluate var="jvar_sysId" expression="RP.getWindowProperties().sysparm_sysid"/>
<g:evaluate jelly="true" object="true">
var rec = new GlideRecord('em_alert');
rec.addQuery('u_case', jelly.sysparm_sysid);
rec.query();
if(rec.next()){
var gr = new GlideRecord("sys_journal_field");
gr.addQuery("element_id",rec.sys_id);
gr.addEncodedQuery("valueLIKEdue to event");
gr.addQuery("element","work_notes");
gr.query();
gr;
}
</g:evaluate>
<table border="1">
<tr><td colspan="2">Event Messages</td></tr>
<tr>
<th>Number</th>
<th>Work Notes</th>
</tr>
<j:while test="${gr.next()}">
<tr>
<td>${gr.number}</td>
<td>${gr.value}</td>
</tr>
</j:while>
</table>
<style>
td, th{
padding: 10px;
}
</style>
</j:jelly>
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2024 03:43 AM
Hello @Gopi12 ,
Please try with the modified script 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">
<h3>Event table</h3>
<g:evaluate var="jvar_sysId" expression="RP.getWindowProperties().sysparm_sysid"/>
<g:evaluate jelly="true" object="true">
var rec = new GlideRecord('em_alert');
rec.addQuery('u_case', jelly.sysparm_sysid);
rec.query();
var alertSysIds = []; // Array to store alert sys_ids
while (rec.next()) {
alertSysIds.push(rec.sys_id.toString());
}
var gr = new GlideRecord("sys_journal_field");
gr.addQuery("element_id", "IN", alertSysIds.join(','));
gr.addEncodedQuery("valueLIKEdue to event");
gr.addQuery("element", "work_notes");
gr.query();
gr;
</g:evaluate>
<table border="1">
<tr><td colspan="2">Event Messages</td></tr>
<tr>
<th>Number</th>
<th>Work Notes</th>
</tr>
<j:while test="${gr.next()}">
<tr>
<td>${gr.number}</td>
<td>${gr.value}</td>
</tr>
</j:while>
</table>
<style>
td, th{
padding: 10px;
}
</style>
</j:jelly>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2024 09:16 AM
Hello @Gopi12 ,
Certainly, if you want to display the number field of the em_alert records instead of the sys_id, you can modify the script accordingly. Here's the updated script:
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<h3>Event table</h3>
<g:evaluate var="jvar_sysId" expression="RP.getWindowProperties().sysparm_sysid"/>
<g:evaluate jelly="true" object="true">
var rec = new GlideRecord('em_alert');
rec.addQuery('u_case', jelly.sysparm_sysid);
rec.query();
var alertNumbers = []; // Array to store alert numbers
while (rec.next()) {
alertNumbers.push(rec.number.toString());
}
var gr = new GlideRecord("sys_journal_field");
gr.addQuery("element_id", "IN", alertNumbers.join(','));
gr.addEncodedQuery("valueLIKEdue to event");
gr.addQuery("element", "work_notes");
gr.orderBy("element_id"); // Order by alert number
gr.query();
var uniqueAlerts = {}; // Use an object to track unique alerts
</g:evaluate>
<table border="1">
<tr><td colspan="2">Event Messages</td></tr>
<tr>
<th>Alert Number</th>
<th>Work Notes</th>
</tr>
<j:while test="${gr.next()}">
<tr>
<td>${gr.element_id}</td>
<td>${gr.value}</td>
</tr>
</j:while>
</table>
<style>
td, th{
padding: 10px;
}
</style>
</j:jelly>
In this modification, I replaced the usage of sys_id with number for the em_alert records. Now, the script should display the alert numbers instead of the sys_ids.
Also if this modification works for you consider marking my solution as helpful and Accept my solution as well.
Thanks,
Aniket
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2024 01:22 AM
Hi @Ankur Bawiskar ,
I am getting all the work notes, but I need to get only specific work notes.
Example: if work notes contain "test" we need to get only those work notes entries.
Thanks in advance...!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2024 01:58 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2024 02:24 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2024 02:39 AM
try this
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<h3>Event table</h3>
<g:evaluate var="jvar_sysId" expression="RP.getWindowProperties().sysparm_sysid"/>
<g:evaluate jelly="true" object="true">
var gr = new GlideRecord("sys_journal_field");
gr.addQuery("element_id",jelly.sysparm_sysid);
gr.addEncodedQuery("valueLIKEdue to event");
gr.addQuery("element","work_notes");
gr.query();
gr;
</g:evaluate>
<table border="1">
<tr><td colspan="2">Event Messages</td></tr>
<tr>
<th>Number</th>
<th>Work Notes</th>
</tr>
<j:while test="${gr.next()}">
<tr>
<td>${gr.number}</td>
<td>${gr.value}</td>
</tr>
</j:while>
</table>
<style>
td, th{
padding: 10px;
}
</style>
</j:jelly>
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader