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

Ticket Conversations - Add Email sent to ticket conversation field.

Christian Graab
Giga Expert

Hello.

I have a problem, where I'm trying to extend the functionality of the Ticket Conversations widget.  

I want to add emails to the view, like in the activites formatter on the form like the picture below.

Screen Shot 2018-01-10 at 12.31.39.png


I have found the data.stream = $sp.getStream(data.table, data.sys_id); in the server side code, looking into this it only returns additional comments.
Since this is in the GlideScriptable API I cannot edit this to return the data i want.  

Is there any way to get emails into the ticket ?

6 REPLIES 6

That's awesome.  I'm going to add your code here below your post, but if this solves the OP's issue makr Chris P. as answerer.

record.stream = $sp.getStream(options.table, record.sys_id);

//Below code adds rows to the array which $sp.getStream creates
var mailgr = new GlideRecord('sys_email');
		mailgr.addQuery('instance',record.sys_id);
		mailgr.query();
		
		while (mailgr.next()) {
			var tempobj = {};
			tempobj.element = "comments";
			tempobj.field_label = "Additional comments";
			tempobj.sys_created_on = mailgr.sys_created_on.toString();
			tempobj.sys_created_on_adjusted = mailgr.sys_created_on.getDisplayValue().toString();
			tempobj.sys_id = mailgr.sys_id.toString();
			tempobj.user_sys_id = 'system';
			tempobj.name = "system";
			if (mailgr.sys_created_by != 'system' || mailgr.mailbox.getDisplayValue() == "Received") { //This filters the creation mail and other assignment group mails etc...
				var usergr = new GlideRecord('sys_user');
				usergr.addQuery('user_name',mailgr.sys_created_by.toString());
				usergr.query();
				if (usergr.next()) {
					tempobj.user_sys_id = usergr.sys_id.toString();
					tempobj.name = usergr.name.toString();
				}
				var mailtype = "";
				if (mailgr.mailbox.getDisplayValue() == 'Sent') mailtype = "<strong>Sent email:</strong> \n";
				else mailtype = "<strong>Received email:</strong> \n";
				tempobj.value = mailtype + mailgr.body_text.toString();
				record.stream.entries.push(tempobj);
			}
// 			else {
// 				tempobj.user_sys_id = '';
// 				tempobj.name = "system";
// 			}
			
		}

//Now we just need to re-sort the array so the output is correct
		record.stream.entries.sort(function(a,b) {return (a.sys_created_on_adjusted < b.sys_created_on_adjusted) ? 1 : ((b.sys_created_on_adjusted < a.sys_created_on_adjusted) ? -1 : 0);} );

jenniferjames
Mega Contributor

I'm facing an issue with extending this Conversations widget. I need to add emails to the view, similar to the activities formatter. The server-side code using data.stream = $sp.getStream(data.table, data.sys_id) only returns additional comments. Is there a way to include emails in the ticket? Thanks!