inbound action update sctask

max_danielewicz
Giga Expert

Hi All,

i do have a catalog item that as part of the workflow (ritm level) sends an email to a vendor.

I created an inbound action to read when the vendor replies to snow and i would like to update the sctask related to the ritm and to create an event. The event will trigger a notification.

The email that the vendor replies has a token related to the ritm.(Ref:MSG0996241).

When i test the inbound action removing the two lines commented, it adds the email to the comments to the ritm, but nothing else.

The inbound action's target table is "sc_req_item"

the action is as follows, but it is not updating the sctask:

gs.include('validators');

if (current.getTableName() == "sc_req_item") {
//current.work_notes = "reply from: " + email.origemail + "\n\n" + email.body_text;
//current.update();
var sysid = current.sys_id;
var gr = new GlideRecord('sc_task');
gr.addQuery('request_item', sysid);
gr.query();
while(gr.next()) {
gr.work_notes = "reply from: " + email.origemail + "\n\n" + email.body_text;
gr.update();
}
}

gs.eventQueue('engage_response',current,null,null);

 

regards,

max

 

1 ACCEPTED SOLUTION

max_danielewicz
Giga Expert

Hi All,

 

here is what it was changed and made it work:

 

gs.include('validators');

if (current.getTableName() == "sc_req_item") {
current.work_notes = "reply from: " + email.origemail + "\n\n" + email.body_text;
current.update();
var sysid = current.number;
var sctask = email.body.task;

var gr = new GlideRecord('sc_task');
gr.addQuery('number', sctask);
gr.query();
while(gr.next()) {
gr.work_notes = "reply from: " + email.origemail + "\n\n" + email.body_text;
var assignedto = gr.assigned_to;
gr.update();
}
}
gs.eventQueue('engage_response',current,sctask,assignedto);

 

regards,

max

View solution in original post

6 REPLIES 6

Phuong Nguyen
Kilo Guru

Hi Max,

Does your query return anything? does the code block inside your if statement execute at all?

Thanks,

Phuong

Hi Phuong,

 

if i remove comments in the following lines, it will update the ritm and create the event. but it will not update the sctask.

//current.work_notes = "reply from: " + email.origemail + "\n\n" + email.body_text;
//current.update();

regards,

max

hi Phuong,

the following statements within the if work.

current.work_notes = "reply from: " + email.origemail + "\n\n" + email.body_text;
current.update();

The rest of the code, does not work.

I changed it to this, so i can get the assigned_to as a parameter but it is not working.

gs.include('validators');

if (current.getTableName() == "sc_req_item") {
current.work_notes = "reply from: " + email.origemail + "\n\n" + email.body_text;
current.update();
var sysid = current.number;
var sctask = email.body.task;

var gr = new GlideRecord('sc_task');
gr.addQuery('request_item', sysid);
gr.query();
while(gr.next()) {
gr.work_notes = "reply from: " + email.origemail + "\n\n" + email.body_text;
var assignedto = gr.assigned_to;
gr.update();
}
}
gs.eventQueue('engage_response',current,assignedto,sctask);

 

 

regards,

max

Hi Max, I recommend moving the current.update(); to the end of your code after the gs.eventQueue() move the event queue code inside the if block then add current.update() after it. I suspect the rest of the code did not run because current.update() was executed. Thanks, Phuong