The CreatorCon Call for Content is officially open! Get started here.

How to populate work notes based on String value(due to event) through ui page on ui action button?

Gopi12
Tera Contributor

Hi @Ankur Bawiskar ,

 

Could please help me in the below script.

Ui action script:

 

   function showEvents() {
       var gm = new GlideModal('event_messages');

       gm.setTitle('Show title');

       gm.setPreference('sysparm_sysid', g_form.getUniqueValue());
       gm.render();


   }
 
Ui Page 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 gr = new GlideRecord("em_alert");
 gr.addQuery("u_case",jelly.sysparm_sysid);
 gr.addQuery("work_notesLIKEdue to event");
   
 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>
 
Thanks & Regards,
Gopi.
2 ACCEPTED SOLUTIONS

@Gopi12 

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.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

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>

 

View solution in original post

25 REPLIES 25

@Gopi12 

I believe I have already answered your original question.

Please mark my response as correct and close the thread.

The discussion can continue on the same thread for further requirement.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Gopi12 

are you saying you want to print info for all alerts belonging to that case?

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi @Ankur Bawiskar ,

 

yes, if case have multiple alerts we need to get all alerts work notes.

 

Thanks,

Gopi.

@Gopi12 

then you need to handle this within g:evaluate tag

query all alerts with this case and store the number and work notes in json object and then iterate this json

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi @Ankur Bawiskar ,

I am new to ui page if you don't mine, Could please provide script for that.

Thanks,

Gopi.