- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2021 04:18 AM
Hi All,
I have requirement in workflow as when task 1 is changed to “Close incomplete” state, a new task should be created.
So in wf I have added following code to check state of task
<
answer = ifScript();
function ifScript(){
var task = new GlideRecord('sc_task');
if(task.get('request_item', current.sys_id)){
if(task.state == '4'){
return 'yes';
}
else{
return 'no';
}
}
}
>
But it's not working in my case. Can you please help me in that
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2021 04:26 AM
Hi,
Please replace your code :
answer = ifScript();
function ifScript(){
var taskGr = new GlideRecord('sc_task');
taskGr.addQuery('request_item', current.sys_id);
taskGr.query();
if(taskGr.next()){
if(taskGr.state == '4'){
return 'yes';
}
else{
return 'no';
}
}
}
Thanks,
Anil Lande
Thanks
Anil Lande

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2021 04:24 AM
It would be handy to know what you mean by "not working" here, but I do see one issue with your script and the nested `if` statements. It's probably more obvious if I indent the code properly here:
answer = ifScript();
function ifScript(){
var task = new GlideRecord('sc_task');
if(task.get('request_item', current.sys_id)){
if(task.state == '4'){
return 'yes';
}
else{
return 'no';
}
}
// there is no default return in the event the task.get fails so it is possible
// to exit this function without returning anything
}
Not sure if this is the source of your problem or not - would need more details.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2021 04:26 AM
Hi,
Please replace your code :
answer = ifScript();
function ifScript(){
var taskGr = new GlideRecord('sc_task');
taskGr.addQuery('request_item', current.sys_id);
taskGr.query();
if(taskGr.next()){
if(taskGr.state == '4'){
return 'yes';
}
else{
return 'no';
}
}
}
Thanks,
Anil Lande
Thanks
Anil Lande
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2021 05:36 AM
Thank you Anil...It's working for me.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2021 05:38 AM
Glad to resolve your issue, could you please mark answer helpful too?
Thanks,
Anil Lande
Thanks
Anil Lande