workflow scratchpad in if condition

RudhraKAM
Tera Guru

I have a workflow in which i have 2 tasks(A,B) on sc_task table , if the task A is closed complete( state=3) then we need to store that value in workflow scratch pad 

In task A in advance section I added "workflow.scratchpad.state1 = task.state;"

and after task b is completed i need to check if the Task A is close complete then i need to create another task if not send to end for this i added If activity to check , I am having issue with the code , it always goes to No even if the state of task A is closed complete.

answer =  ifScript();

function ifScript(){
workflow.scratchpad.state1;
var gr = new GlideRecord('sc_task');
gr.addQuery('parent',current.sys_id);   //Copied this code from some other thread, is this condition valid ?
gr.query();
if(gr.next()){
if (workflow.scratchpad.state1 == 3) {    //3 is closed complete
return 'yes';
}
else
return 'no';
}
}
1 ACCEPTED SOLUTION

Hello,

As stated above, you can glide the sc_task table and get the state using the sys_id scratchpad...

So in that same mindset...you can assign that state value to a scratchpad and use it elsewhere...or...just glide and get it...

This thread is going all over the place and I'm confused if you're reading what I wrote. All you did here is just copy and paste the same script from your original post. I don't need to see it again...

For your script...you need to gliderecord query the sc_task table and use the sys_id from the scratchpad...

answer =  ifScript();

function ifScript(){
var gr = new GlideRecord('sc_task');
gr.addQuery('sys_id', workflow.scratchpad.taskID);
gr.query();
if(gr.next()){
if (gr.state == 3) {
return 'yes';
} else {
return 'no';
  }
 }
}

 

Please mark reply as Helpful/Correct and any other post as Helpful, if it was.

Thanks

 


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

View solution in original post

12 REPLIES 12

Mark Roethof
Tera Patron
Tera Patron

Hi there,

The 4th line, workflow.scratchpad.state1;, what should this be? This now really looks odd. You already defined the scratchpad.state1 in an earlier utility I assume?

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

Yes i added that in task A to store the State value

Mark Roethof
Tera Patron
Tera Patron

Rethinking what you wrote, why are you doing this with an If utility? Why not just with the Conditions on the Task Utility itself?

See for example this article which I wrote a few weeks ago. You can simply add a condition for if the task was Complete, Incomplete, etc..
https://community.servicenow.com/community?id=community_article&sys_id=3e375ad5db9bc010414eeeb5ca961...

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

The issue is after Task A it will go to TasK B and then some other activities ,, after 10 more activities then we are checking if the Task A activity is close complete then create another task ,, if the state is close incomplete then end the workflow , that's why i am using workflow scratch pad