Close Task via Email

SimonRudd
Kilo Explorer

Hi All,

 

To make life easier for our Service Desk, we would like the option to close tasks via an email response (similar to approvals). The idea is that the Service Desk would receive an email saying that a task is assigned to them and they have the option to either Close Complete or Close Reject.

This is based on Requests (REQ -> RITM -> TASK) and we would want the TASK to be closed.

I have tried creating an email template (using the 'mailto: approval' template as a base) and also an inbound action based on type being 'reply' and the table being task or catalog task. I have tried the following scripts, as found on the community, as an inbound action and neither work on the task or catalog task tables (these scripts are based just on close completing, to start)

SCRIPT 1

var temp =email.subject.toString().toLowerCase();

if(temp.indexOf("close task") > 0)

current.state= 3; //closed state

current.update();

SCRIPT 2

gs.include('validators');  

if (current.getTableName() == "incident") {  

if (email.subject.toLowerCase().indexOf("close task") >= 0) {  

current.incident_state= 3;

current.incident_state.setValue(3);

current.active= false;

current.work_notes= "The caller agreed that this issue was resolved";

}  

current.update();              

}

Is there something obviously wrong and/or is there an easier way to implement this functionality.

Any help or advice would be greatly appreciated.


Simon

10 REPLIES 10

SimonRudd
Kilo Explorer

Hi Brad,



Thanks for the response. Apologies - the second script should read the below (I copied straight from the community feed rather than the instance!) - I have also tried the same script using sc_task instead of task.



SCRIPT 2


gs.include('validators');  


if (current.getTableName() == "task") {  


if (email.subject.toLowerCase().indexOf("close task") >= 0) {  


current.state= 3;


current.state.setValue(3);


current.active= false;


current.work_notes= "The caller agreed that this issue was resolved";


}  


current.update();              


}



I have tried amending the SCRIPT 1 with the > -1 or >= 0 but that has not worked. Again, I have tried it using the task and sc_task tables.



Simon


You would want the table to be sc_task, but I don't see anything else that stands out.



At this point I would do some standard script troubleshooting. Add some gs.log statements throughout your script to see if it stops executing somewhere or if a value is not setting, etc. You also might try a try/catch block.



Debugging Tools Best Practices - ServiceNow Wiki


Logs and Queues Best Practices - ServiceNow Wiki


Viewing System Logs - ServiceNow Wiki


OK no problem - I will do some troubleshooting etc to see if anything stands out - it is a weird one!



Thanks Brad, will keep you updated.



Simon.


Hi Simon,

Did you ever get this working?  We're looking to do the same.

 

Cheers

Carl.

No luck to get this achieved.