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

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.

@asifnoor  - Would I be able to use a wait for condition. In the wait for condition query the request and related ritm to the SCTASK and close the RITM instead?

The wait for condition in the WF will execute only when the underlying table defined in the workflow is updated everytime. If catalog task is closed then the wait for conditons which was defined on request table will not execute. Hence you need a Br on catalog task which updates the request whenever a task is closed.

Once the request is closed, then the WF wait for conditions runs and in that you can also close the ritm along with closing the request.

Mark the comment as a correct answer and also helpful if this helps to solve the problem.

Mark Roethof
Tera Patron
Tera Patron

Hi there,

Within the script field of the Create Task, you could set up a scratchpad. Just using something like:

workflow.scratchpad.something = task.number;

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

Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP

---

LinkedIn
Community article list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

My ultimate goal is to close the request once the task is closed complete and this should all be performed in the workflow. 

Would I do what you said but instead change the value to:

workflow.scratchpad.something = task.state;

Then in the next flow add an IF statement, state changes to closed complete set state on REQ to closed complete?