How to check state of catalog task is Closed incomplete

Harshada Phadke
Tera Contributor

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

1 ACCEPTED SOLUTION

Anil Lande
Kilo Patron

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

View solution in original post

4 REPLIES 4

Michael Nichols
Giga Contributor

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.

Anil Lande
Kilo Patron

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

Thank you Anil...It's working for me.

Glad to resolve your issue, could you please mark answer helpful too?

 

Thanks,

Anil Lande