How to get SCTASK number in workflow

mkader
Kilo Guru

Hello,

I have a workflow on sc_request table that creates an sctask. It is a simple workflow:

Begin > Create Task > End

I want to store the value as a workflow scratchpad or a set value so that when the sc_task is closed, I can close a RITM being created through another workflow on the same REQ. 

Thanks!

1 ACCEPTED SOLUTION

Okay.

The WF will not know if the task is closed as WF is runnig on request table. So you nee dto update the request for the WF code to run.

May be you can do1 thing. Use the Br tht i  gave when task is clsoed update the request work notes.

Then in your workflow add  a wait for condition

// Set the variable 'answer' to true or false to indicate if the condition has been met or not.
var flag=0;
var gr = new GlideRecord("sc_task");
gr.addQuery("request",current.sys_id);
gr.query();
while(gr.next()) {
  if(gr.state == 3) {     
     flag++;    
  } 
}
if(flag == gr.getRowCount()) {
  answer = true;
} else {
  answer = false;
}

Then link the set values activity and make the request as closed.

The Wait for condition will run when the request is updated. And you update the request with the BR on sc_task table.

View solution in original post

13 REPLIES 13

Yash Agrawal1
Tera Guru

Hello USer,

Try the below one.

var arr=[];
var gr = new GlideRecord("sc_task");
gr.addQuery("request", current.sys_id);
gr.query();
while (gr.next()) //dont use if,if will give you only one task number.what if you have utiple task so use while
{
    arr.push(gr.getUniqueValue();
    //workflow.scratchpad.num = gr.number;
}

Please Mark it helpful/correct if my answer helps in any way to resolve your query.
Reach out to me if any more help required.

Regards

Yash.K.Agrawal

Heello mkder

As said,if condition will give you only one task numner.while will give you all the task number which have same request.

Dont you think the same?

Please keeep posted for more help

Regards

Yash Agrawal

Gaurav Shirsat
Mega Sage

Hi 

In addition to Yash,I would like to add some my views as

var sc_task = new GlideRecord('sc_task');//Glide the  sc_task

sc_task.addQuery('request_item',current.sys_id);//your requested ,request item is this ritm

sc_task.OrderByDesc('sys_created_on');//

sc_task.setLimit(1);

sc_task.query();

if(sc_task.next()){

    workflow.scratchpad.sc_task = sc_task.number;

}

after this you will have to refer to workflow.scratchpad.sc_task to get that sc_task's value;

Please Mark Correct and Helpful

Thanks and Regards

Gaurav Shirsat

Aishwarya Theva
Tera Guru

Hello,

 

Basically for you to close the request which created the sc task you need to add a wait for condition with a script checking the state of the sc task after you getting the sc task through scratchpad, once the closing condition is met you could close the request.

Putting if condition will not work as it will check the current value and complete the workflow.

Hope this helps! 

If my answer helped you in any way, please then mark it as helpful.

 

Regards

Aishwarya Thevar