Change Variable action with if-then-else tree - Mendix Forum

Change Variable action with if-then-else tree

0

Hello,

I'm trying to write an app that takes enumerated status from 5 different project phases and consolidates them into a single overall status based on specific rules.  There are 5 enumerated status types.  The goal is to set the variable ("NewStatus") with the result.  Here's a copy of the Change Variable if-the-else expression -- with many of the names abbreviated.   Based on the research I've done, this should work.  However, I'm getting an error: mismatched input 'AND' expecting ')'

if ( $Eval/PRS = MFM.StatEnum.Not_Started AND $Eval/PSS = MFM.StatEnum.Not_Started AND $Eval/PC1S = MFM.StatEnum.Not_Started AND $Eval/PC2S = MFM.StatEnum.Not_Started AND $Eval/PDS = MFM.StatEnum.Not_Started)
    then 'Not Started'
    else if ( $Eval/PDS = MFM.StatEnum.Completed )
          then 'Completed'
          else if ($Eval/PRS = MFM.StatEnum.Deferred OR $Eval/PSS = MFM.StatEnum.Deferred OR $Eval/PC1S = MFM.StatEnum.Deferred OR $Eval/PC2S = MFM.StatEnum.Deferred OR $Eval/PDS = MFM.StatEnum.Deferred)
                 then 'Deferred'
                 else if ($Eval/PRS = MFM.StatEnum.Waiting OR $Eval/PSS = MFM.StatEnum.Waiting OR $Eval/PC1S = MFM.StatEnum.Waiting OR $Eval/PC2S = MFM.StatEnum.Waiting OR $Eval/PDS = MFM.StatEnum.Waiting)
                       then 'Waiting on someone else'
                       else 'In Progress'

 I tried to do it with splits, but it got unwieldy.  I would greatly appreciate any guidance you could provide on how to make it work and/or make it work more efficiently. 

 

asked
1 answers
3

Mike,

You should replace the uppercase AND and OR with the lowercase version to get this:

if ( 
$Eval/PRS = MFM.StatEnum.Not_Started and 
$Eval/PSS = MFM.StatEnum.Not_Started and 
$Eval/PC1S = MFM.StatEnum.Not_Started and 
$Eval/PC2S = MFM.StatEnum.Not_Started and 
$Eval/PDS = MFM.StatEnum.Not_Started)    
then MFM.StatEnum.Not_Started   
else if ( $Eval/PDS = MFM.StatEnum.Completed )          
then MFM.StatEnum.Completed
else if (
$Eval/PRS = MFM.StatEnum.Deferred or 
$Eval/PSS = MFM.StatEnum.Deferred or 
$Eval/PC1S = MFM.StatEnum.Deferred or 
$Eval/PC2S = MFM.StatEnum.Deferred or 
$Eval/PDS = MFM.StatEnum.Deferred)    
then MFM.StatEnum.Deferred
else if (
$Eval/PRS = MFM.StatEnum.Waiting or 
$Eval/PSS = MFM.StatEnum.Waiting or 
$Eval/PC1S = MFM.StatEnum.Waiting or 
$Eval/PC2S = MFM.StatEnum.Waiting or 
$Eval/PDS = MFM.StatEnum.Waiting)                       
then MFM.StatEnum.Waiting
else MFM.StatEnum.In_Progress

This will remove the errors and work for you.

Be aware that the result of an exclusive split should be a boolean or an enumeration, that's why I changed the parts after the then as I tested this in a split. When using this in a change object activity the string option can be used.

I would however suggest to use a split for this and multiple change object activities for better readability.

answered