Close Service Catalog Task via Email

rba-chris
Kilo Expert

Hi Everyone,

I'm trying to automatically close a service catalog task based on and end user clicking on a link in an automatically-sent email. Here's the inbound action script that I'm trying to use:

closeUserAcceptanceTask();  

     

function closeUserAcceptanceTask(){

// Go through all of the RITMs in this REQ and see if they are approved

var gr_task = new GlideRecord('sc_task');

gr_task.addActiveQuery();

gr_task.addQuery('sc_req_item', current.request_item.request);

gr_task.addQuery('short_description', 'STARTSWITH', 'User Acceptance');

gr_task.query();

while(gr_task.next()) {

gr_task.state = "closed_complete";

}

}

I have also checked out the following URL, but I couldn't get it working either:

https://community.servicenow.com/thread/176755?q=Close%20Service%20Catalog%20Task%20via%20Email

Thanks in advance for your help.

1 ACCEPTED SOLUTION

Thanks so much - this was resolved by a co-worker. If anyone's interested in the solution, I can then type it out at another date - it's too long to do unless someone asks. Many thanks for everyone's time and effort - you got me closer to the solution that you may know!


View solution in original post

21 REPLIES 21

try now.



write inbound action on sc_task table.



gs.include('validators');


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


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


current.state= "2";   //<value of close state here i have mentioned 2 because my close state value is 2>


}


current.update();


}


Harsh,


we don't know that his email subject has close task in it or not.


try without that condition. but it would be good if user will mention some word (close) so it will be easy to execute the script.


The email subject line is New Device Accepted. So I would use this?




gs.include('validators');


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


if (email.subject.toLowerCase().indexOf("New Device Accepted") >= 0) {


current.state= "3";


}


current.update();


}


make it in small word. because you have used toLowerCase(). also make sure when to run set to "reply" in inbound action.



if (email.subject.toLowerCase().indexOf("new device accepted") >= 0) {