if Condition Workflow Activity

ShivangiC
Tera Contributor

I need to define the 'if ' condition on workflow after the 3rd catalog task, to check if a sample checkbox is checked on the 3rd catalog task or not. Please help me. As every time, the if condition is executing for 'No'.

My script in if condition'-

 answer = checkBox();

   function checkBox() {
    if (current.u_sample_checkbox == true) {
        return 'yes';
     }
    else{
     return 'no';}
  }
 
 
My question:- the script in if condition must be server script or client script?. Can we use GlideRecord functionality in if condition?. As my workflow is running on sc_req_item table and if condition must run for sc_task table record
1 ACCEPTED SOLUTION

Aditya Banka2
Tera Guru

AdityaBanka2_0-1725193182284.png

In your third catalog task use the below in advanced

 

workflow.scratchpad.taskSysID = task.setNewGuid();

 

then an if condition with below script

answer = ifScript();

function ifScript() {
var rec = new GlideRecord('sc_task');
rec.get(workflow.scratchpad.taskSysID);
rec.query();
if (rec.hasNext()){
    if( rec.u_sample_checkbox == true)  {
    return 'yes';}
}
return 'no';
}
 
then as per the screenshot, create a task.
 
 

Please mark reply as Helpful/Correct. Thanks!


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

 

View solution in original post

8 REPLIES 8

Aditya Banka2
Tera Guru

Hello Shivani,

 

What are you trying to achieve here. 

If the checkbox is true, what action do you need to take and if it is false, what are you trying to do. Please explain. Check the following

 

In your third create task script, retrieve the task sys_id in the advanced script section of the task activity in the workflow like : workflow.scratchpad.taskSysID = task.setNewGuid();

 

Then, in run script, you can use it like :

var gr2 = new GlideRecord('sc_task');
gr2.get(workflow.scratchpad.taskSysID);
gr2.addQuery('u_sample_checkbox', true);
gr2.query();

if (gr2.hasNext()){

//DO some action
gr2.update();
}
else
{
//DO some action
gr2.update();
}
 

Please mark reply as Helpful/Correct. Thanks!


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

Hello @Aditya Banka2 ,

I am describing you my requirement which is to be achieved by using Workflows. Here it is :-

Create 4 Catalog tasks whenver a new record is inserted/created on sc_req_item table [that is why, Workflow is running on sc_req_item table] but on the 3rd Task (sc_task) Create a Field as CheckBox, if checkbox is checked, create a 4th task, with short Description -> This checkbox was ticked

and if checkbox if unchecked, short Description -> Thischeckbox was unticked.

Aditya Banka2
Tera Guru

AdityaBanka2_0-1725193182284.png

In your third catalog task use the below in advanced

 

workflow.scratchpad.taskSysID = task.setNewGuid();

 

then an if condition with below script

answer = ifScript();

function ifScript() {
var rec = new GlideRecord('sc_task');
rec.get(workflow.scratchpad.taskSysID);
rec.query();
if (rec.hasNext()){
    if( rec.u_sample_checkbox == true)  {
    return 'yes';}
}
return 'no';
}
 
then as per the screenshot, create a task.
 
 

Please mark reply as Helpful/Correct. Thanks!


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

 

Aditya Banka2
Tera Guru

Accept Solution, if applicable. Thanks!