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

Yes, You can do a GlideRecord.

 

Assuming u_sample_checkbox is defined on the catalog task and since the workflow runs on sc_req_item table, you cannot use current.u_sample_checkbox.  Trywith below sample code

 

Ex:

 

function ifScript() {
var rec = new GlideRecord('sc_task');
rec.addQuery('request_item', current.sys_id);
rec.addQuery('u_sample_checkbox', true);  //Check for sample checkbox variable here
rec.query();
if (rec.hasNext()){
return 'no';
}
return 'yes';
}
 
If my answer helped you in any way, please then mark it as helpful or correct.

and to call the function should I write--> answer = ifScript(); or

activity.result=ifScript();

ShivangiC
Tera Contributor

Hello,

I didn't checkbox was 'true' i.e. checkbox is checked why are we returning No here. Please explain your code. I wrote your code as :-

activity.result =ifScript();

function ifScript() {
var rec = new GlideRecord('sc_task');
rec.addQuery('request_item', current.sys_id);
rec.query();

if (rec.hasNext()){
    if( rec.u_sample_checkbox == true)  {
    return 'no';}
}
return 'yes';
}

ShivangiC
Tera Contributor

Your provided solution always return 'yes' i.e.  return statement outside if block. Please provide any other solution