Query SCTASK from Request
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-24-2017 09:35 AM
I'm deploying a UI action that allows users to convert an INC to a Request item in the service catalog. Upon creation, I want to redirect the fulfiller to the newly created SCTASK (Note: Not the REQ or RITM).
function serverResolve(){
var cartId = GlideGuid.generate(null);
var cart = new Cart(cartId);
var item = cart.addItem('17c590e9047531006802a6e8a2359514'); // sys_ID for the request sc_catalog item
cart.setVariable(item, 'u_requested_for', current.u_requested_for);
cart.setVariable(item, 'description', current.comments.getJournalEntry(-1));
var rc = cart.placeOrder();
if(!rc){
gs.addInfoMessage("Error: Request was not created.");
}
//Resolve the current incident upon request creation
current.state = 6; //Resolved
current.close_code = "Closed/Resolved by Caller";
current.close_notes = "Converted to Request: " + rc.number;
current.update();
current.resolved_by = gs.getUserID();
// Retrieve SCTASK Number (Request -> SC Task ->Task number)
var sctask = new GlideRecord('sc_task');
sctask.addQuery('request_item', '=',rc.number);
sctask.query();
var task = new GlideRecord('task');
task.addQuery('number','=',sctask.number);
task.query(callback);
function callback(gr){
while (gr.next()){
gs.addInfoMessage("Request " + task.number + " created.");
}
}
gs.addInfoMessage("Incident " + incident.number + " has been resolved.");
action.setRedirectURL(task);
action.setReturnURL(current);
}
I know the issue is in 23-27, I'm probably querying things in the wrong order.
Thoughts?
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-24-2017 09:51 AM
Hi Bryan,
Please rather use the code:
- var sctask = new GlideRecord('sc_task');
- sctask.addQuery('request_item', rc); //assuming rc stores the sys id of the RITM
- sctask.query()// else all values are returned
- if(sctask.next()){
- var task = new GlideRecord('task');
- task.addQuery('number','=',sctask.number);
- task.query(callback);
- //var nu
- }
- function callback(gr){
- while (gr.next()){ // can be replaced by if
- gs.addInfoMessage("Request " + task.number + " created.");
- //return gr.sys_id;
- }
- }
- gs.addInfoMessage("Incident " + incident.number + " has been resolved.");
- action.setRedirectURL("sc_task.do?sys_id=" +sctask.sys_id);
- action.setReturnURL(current); // not required
- }
I hope this helps..

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-24-2017 09:55 AM
Hi Bryan,
I beleive issue is in the line no 24 rc.number, since you are querying the sc_task table with RITM number, however you are entering request number(REQ) over there instead of request item number(RITM)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-24-2017 12:09 PM
Hello Bryan,
2 things:
1. rc is the object pointing to the REQ, not RITM. So, in your code line 24, replace 'request_item' with 'request'
2. After line 25 - sctask.query(), there's no statement that takes the object to point to the first record in the query.
If you add sctask.next() after line 25, and update line 24 as mentioned above, it should work.