Need help querying Request table from SC_Task table

alhicks
Tera Guru

Need help please with Business Rule, querying the request table from the sc_task table to see if the parent request has any tasks already open.  We need subsequent tasks to detect the other tasks and pick up the same assigned to person.

Of course this isn't working. 😞

var gr = new GlideRecord('sc_task');
gr.addQuery('sys_id',current.request_item.request);
gr.query();

while (gr.next()) {
if(current.request_item.request == gr.request_item.request){
gr.assigned_to = current.assigned_to;

1 ACCEPTED SOLUTION

var gr = new GlideRecord('sc_task'); 
gr.addQuery('request_item.request', current.request_item.request);
gr.query();

while (gr.next()) { 
    if(gr.assigned_to) {
       current.assigned_to = gr.assigned_to;
       current.update();
    }
}

This will assign the new task to whoever is assigned to other tasks. Is this what you're looking for?

View solution in original post

4 REPLIES 4

Elijah Aromola
Mega Sage

If I'm understanding your requirement correctly this code should work. If it's a before business rule, get rid of gr.update():

var gr = new GlideRecord('sc_task'); 
gr.addQuery('request_item', current.request_item);
gr.query();

while (gr.next()) { 
    if(gr.assigned_to){
         gr.assigned_to = current.assigned_to;
         gr.update()
    }
}

Please mark this as correct/helpful if it resolved your issue!

Thank you Elijah, I'm trying to query the Request number from the Catalog Task.  And if the Task being created have the same request number, then assign those Task to the same technician.  🙂

var gr = new GlideRecord('sc_task'); 
gr.addQuery('request_item.request', current.request_item.request);
gr.query();

while (gr.next()) { 
    if(gr.assigned_to) {
       current.assigned_to = gr.assigned_to;
       current.update();
    }
}

This will assign the new task to whoever is assigned to other tasks. Is this what you're looking for?

Abhinay Erra
Giga Sage

You have request field available on the catalog task table. You do not need to dot walk from request item

 

var gr = new GlideRecord('sc_task'); 
gr.addQuery('request', current.request);
gr.query();
while (gr.next()) { 
    if(gr.assigned_to) {
       current.assigned_to = gr.assigned_to;
    }
}