- 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 01:04 AM
so what's not working?
what debugging have you done so far?
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 01:19 AM - edited 01-23-2024 01:27 AM
Hello @Gopi12 ,
Modified the UI Page script based on your recent feedback on the question to filter the work notes based on the text
gr.addQuery("work_notes", "LIKE", "test");
Modify the UI Page Script: Update the UI page script to include a function that adds work notes based on a string value. In your case, it seems like you want to query the em_alert table for records related to the specified u_case and containing a specific string in the work_notes field.
<?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("em_alert");
gr.addQuery("u_case", jelly.sysparm_sysid);
gr.addQuery("work_notes", "LIKE", "due to event"); // Adjust the query as needed
gr.addQuery("work_notes", "LIKE", "test"); // Add this line to filter based on "test"
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>
<j2:while test="$[gr.next()]">
<tr>
<td>$[gr.number]</td>
<td>$[gr.work_notes.getJournalEntry(-1)]</td>
</tr>
</j2:while>
</table>
<style>
td, th{
padding: 10px;
}
</style>
</j:jelly>
Modify the UI Action Script: Update the UI action script to call the function that populates work notes. Here's an example:
function showEvents() {
var gm = new GlideModal('event_messages');
gm.setTitle('Show title');
gm.setPreference('sysparm_sysid', g_form.getUniqueValue());
gm.render();
// Call the function to populate work notes based on the string value
populateWorkNotes();
}
// Function to populate work notes based on the specified criteria
function populateWorkNotes() {
// You can add any additional logic here if needed
// For example, you may want to reload the modal after updating work notes
// or perform other actions.
// You can use GlideAjax or other methods to update the records.
// For simplicity, you can reload the current form after updating work notes
g_form.save(); // Save the form to trigger reload with updated work notes
}
Let me know your views on this and Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Thanks,
Aniket
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2024 01:35 AM
Hi @Aniket Chavan ,
Could please tell me about the script for to give specific string in the function.
populateWorkNotes(); } // Function to populate work notes based on the specified criteria function populateWorkNotes() { // You can add any additional logic here if needed // For example, you may want to reload the modal after updating work notes // or perform other actions. // You can use GlideAjax or other methods to update the records. // For simplicity, you can reload the current form after updating work notes g_form.save(); // Save the form to trigger reload with updated work notes }
Thanks in Advance..!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2024 01:43 AM
Hello @Gopi29 ,
You can try with something like below ,
function showEvents() {
var gm = new GlideModal('event_messages');
gm.setTitle('Show title');
gm.setPreference('sysparm_sysid', g_form.getUniqueValue());
gm.render();
// Call the function to populate work notes based on the string "test"
populateWorkNotes("test");
}
// Function to populate work notes based on the specified criteria
function populateWorkNotes(filterString) {
// You can add any additional logic here if needed
// For example, you may want to reload the modal after updating work notes
// or perform other actions.
// Query the records based on the filterString
var gr = new GlideRecord("em_alert");
gr.addQuery("u_case", g_form.getUniqueValue());
gr.addQuery("work_notes", "LIKE", filterString);
gr.query();
// Loop through the records and perform actions
while (gr.next()) {
// Perform actions with the retrieved records, e.g., update or log
// For example: gr.work_notes = "Updated work notes";
// gr.update();
}
// For simplicity, you can reload the current form after updating work notes
g_form.save(); // Save the form to trigger reload with updated work notes
}