Update the State, Copy Attachments, Comments from Reply Email to Req Item

Biso_Boby
Tera Contributor

I have a requirement where the Assigned to person clicks on 'Send Email' UI Action on SC Task , it sends an email to Requested By & Watch List of Req Item Record. 

 

So if the Requested By/Watch List person responds to that email, state of the ticket should change from Awaiting Response to Work in Progress and any attachment/comment sends as part of response should be copied over to Req Item & SC Task. 

 

Can someone assist on this, how to  implement?

 

@Ankur Bawiskar @Sandeep Rajput @SANDEEP DUTTA 

2 REPLIES 2

AyushKumarM
Mega Guru

Hey @Biso_Boby ,

You should use inbound email actions for this. Please refer to this link : Inbound email actions.

You can use something like this, 

(function runAction(email, event) {
var task = email.target;
if (!task || task.getTableName() != 'sc_task')
return;

var ritm = task.request_item.getRefRecord();

// If state is Awaiting Response -> move to WIP
if (task.state == 15) { // assuming 15 = Awaiting Response
task.state = 2; // Work in Progress
task.update();
}

// Add comments from email
var bodyText = email.body_text;
if (bodyText) {
task.work_notes = "Response received via email:\n" + bodyText;
task.update();
if (ritm) {
ritm.comments = "Response received via email:\n" + bodyText;
ritm.update();
}
}

// Attachments: copy them from email to task and ritm
var attachGR = new GlideRecord('sys_attachment');
attachGR.addQuery('table_sys_id', email.sys_id);
attachGR.query();
while (attachGR.next()) {
GlideSysAttachment.copy('sys_email', email.sys_id, 'sc_task', task.sys_id);
if (ritm)
GlideSysAttachment.copy('sys_email', email.sys_id, 'sc_req_item', ritm.sys_id);
}
})(email, event);


Hope this helps. 
Thanks and regards,
Ayush

 



Ankur Bawiskar
Tera Patron
Tera Patron

@Biso_Boby 

so what did you start with and where are you stuck?

1) you can have UI action and use server side logic to trigger event which leads to email using gs.eventQueue()

2) then you can have inbound action on sc_task of type Reply and update the SC Task

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