Need to Display last 3 entries of work notes in one by one order in table format in notification?

Ramu6
Tera Contributor

Hi All, 

Actually we have notification that will displaying the worknotes as one column in table format in notification like below

Ramu6_0-1705909612177.png

and the email script to display this is below

Ramu6_1-1705909702367.png

So now my concern was the work notes has needs be display in proper order one by one like this

Ramu6_0-1705916461376.png

 

 

 

 

Please help me to complete this

Thanks

Ramu

5 REPLIES 5

Ankur Bawiskar
Tera Patron
Tera Patron

@Ramu6 

this is the sample code to get latest 3 values.

please enhance it by adding code in your email script and use proper html table tags

(function runMailScript(current, template, email, email_action, event) {

	// Add your code here

	var fieldName = 'work_notes';

	var rec = new GlideRecord('sys_journal_field');
	rec.orderByDesc('sys_created_on');
	rec.addQuery('name', current.getTableName());
	rec.addQuery('element', fieldName);
	rec.addQuery('element_id', current.sys_id);
	rec.setLimit(3);
	rec.query();
	while(rec.next()){
		template.print(rec.value);
	}

})(current, template, email, email_action, event);

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

@Ankur Bawiskar 

Thanks for the response

Actually i am not sure where i need to do changes in my script , so my email script was , actually this is we create for tabular format

 

var tableHTMLUtils = new CG_EmailTableUtils();
 
 
var fields = ["number","short_description", "description","work_notes","sys_updated_by"];
 
var rowData=new CG_EmailTableUtils().addFields(fields,current);
 
rowData.forEach(function(key){
tableHTMLUtils.addRow(key);
});
template.print(tableHTMLUtils.getTableHTML());
 
Script include is
Ramu6_0-1705914115619.png

Can you please help me to where i have to replace the code?

 

Thanks

Ramu

 

@Ramu6 

I already shared the logic on how to fetch 3 latest work notes

Now the next part is what you can enhance from your side.

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

@Ankur Bawiskar 

Actually my script also is fine but it display the work notes not in a proper order, so my concern is like need to display those worknotes in proper order like this order

 

Ramu6_0-1705916491244.png