workflows - branched IF conditions

mrswann
Kilo Guru

I previously had this working from the mini-lab https://community.servicenow.com/community/develop/blog/2015/10/18/mini-lab-workflows--playing-with-...  

On a different project now and I want to employ the same again...

I am struggling to get the Condition to pay attention to the results in the script??

The script as follows:

activity = ifScript();

function ifScript() {

      var result = {VALUE1:false,VALUE2:false, VALUE3:false, VALUE4:false};

      if (VariableFieldValue == 'true') {

                      result.VALUE1 = true;

      }

result.VALUE2 = true;

result.VALUE3 = 'true';

return result;

}

I have 4 conditions for the IF statement branches,

find_real_file.png

find_real_file.png

and so on...

I have also included some logs in the script and can see that the result.VALUEs are being updated, so it seems I am accessing the values incorrectly in the conditions to catch the output flows

when i had it without activity.result and just result.VALUE (no activity.) it was throwing an unbound or wrapped exception on result

10 REPLIES 10

Chuck Tomasi
Tera Patron

You seem to be inconsistent in your boolean values.



Be careful how you are using true and 'true'. The first is a boolean and the second is a string. Either is valid as long as you are consistent. However if you set a variable   like this:



var myVar = 'true';



This does not evaluate to true



if (myVar == true)



or if you set it to



myVar = 'false';



then THIS actually resolves to TRUE!



if (myVar)



because it is just checking for a non-null string value.


Indeed and I apologise for confusion.



The first check about the variable, I believe comes in as a string. It is a checkbox display value?




The other inconsistencies are because I was trialling and erroring as part of a debug. Prior to that I was utilising pure boolean as activity.result.VALUEs , so if we assume all are set as boolean, and the condition is checking as boolean - what else could I be doing wrong?


Kalaiarasan Pus
Giga Sage

Why not use a switch instead of 'If' block?


I need to be able to fire these simultaneously they are not mutually exclusive