- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-12-2018 12:34 PM
I have a request item with a workflow attached. There are a series of steps in the workflow, each one creating a sc_task record. However, each step in the process waits for the previous task to be completed before generating the next task (wait for completion is checked in the workflow).
I have an inbound action script that closes a task. My problem is that when I close the task with the script, the task appears to re-generate itself instead of proceeding to the next task (the original is closed, but a duplicate is created).
It's probably important to note that the inbound action is written on the incident table. It's for new emails that don't contain a watermark. I search request item variables. If I find a match, I update the request item and close the current task. If I don't find a match, I insert an incident.
Here are the important pieces of the script:
// Find active request item variables matching tracking number from email
var gr = new GlideRecord('sc_item_option_mtom');
gr.addQuery('sc_item_option.item_option_new.name','name'); // variable name
gr.addQuery('sc_item_option.value',email.body.value); // variable value from email
gr.addQuery('request_item.active',true); // active request items
gr.query(); // execute query
// set GlideRecord for request item containing matching variable
var reqitem = new GlideRecord('sc_req_item');
reqitem.addQuery('number',gr.request_item.number); // dot-walk from variable to request item, getting request item number
reqitem.query(); // execute query
// update request item
if (reqitem.next()) {
//update some stuff on request item
reqitem.update();
// close request item task
var sctask = new GlideRecord('sc_task');
sctask.addQuery('request_item',reqitem.sys_id); // tasks related to request item
sctask.addQuery('active',true); // active tasks
sctask.query(); // execute query
if (sctask.next()) {
sctask.state = 3; // set state to Closed Complete
sctask.update(); // update task
}
}
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-12-2018 09:03 PM
Can you add if(gr.next()) after gr.query(); and try.
if(gr.next()){
//All the code
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-12-2018 09:03 PM
Can you add if(gr.next()) after gr.query(); and try.
if(gr.next()){
//All the code
}