- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-07-2020 06:18 AM
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';
}
}
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-07-2020 06:49 AM
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!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-07-2020 06:31 AM
Hello,
That is because when you're within task A and in that script section...you are setting the scratchpad to its state at that time...when it was created...that doesn't mean it's getting the state from that task when it's finished.
So instead...you'd want to gliderecord in this IF activity to check the state from task A.
What you can do instead of grabbing the state in task A, you can do this:
workflow.scratchpad.taskID = task.setNewGuid();
Then in your if activity glide...use that scratchpad with the sys_id to quickly check state.
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-07-2020 06:37 AM
thanks Allen , is there a way to capture the state when the task state changes to close complete or close incomplete and use it else where ?
and in if condition this is the script i am using can you please correct me if i am missing anything
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';
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-07-2020 06:49 AM
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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-07-2020 06:54 AM
Sorry Allen , for some reason it didnt see your full reply , so as you mentioned I added"
workflow.scratchpad.taskID = task.setNewGuid();
" the in Task A
and in if condition i am using this scrip can you please help me with this script
//workflow.scratchpad.taskID = task.setNewGuid();
answer = ifScript();
function ifScript(){
var gr = new GlideRecord('sc_task');
gr.addQuery('parent',current.sys_id); //Is this correct ? This task has no parent
gr.query();
if(gr.next()){
if (workflow.scratchpad.taskID == 3) { // do we compare with the name or value ?
return 'yes';
}
else
return 'no';
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-07-2020 07:09 AM