Announcement

Collapse
No announcement yet.

ifThen or nested ifThenElse? Contacts Formula

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • ifThen or nested ifThenElse? Contacts Formula

    I'm tying to calculate a % based on a drop down (ESI, PSI, etc.) each of which have a difference maximum score.

    I don't know the correct code to keep the calculation from always using the last calculation listed ("PRA"/92) no matter what is selected in the drop down; doesn't seem to ignore the PRA when I select USI, for instance, like the documentation suggests:
    ifThen(CONDITION, CONSEQUENT)

    If CONDITION is met, then do CONSEQUENT. If not - do nothing.

    I saw somewhere using something like $prePC = ""/$prePC=prePC but I cannot get that to work, also tried a nested IfThenElse,

    can someone please assist?
    ifThen(preTest = 'ESI', prePC = (startingScore/87)*100;
    );
    ifThen(preTest = 'PSI', prePC = (startingScore/82)*100;
    );
    ifThen(preTest = 'USI', prePC = (startingScore/99)*100;
    );
    ifThen(preTest = 'PRA', prePC = (startingScore/92)*100;
    );

  • #2
    Hello crmclients ,

    Try this option with == instead of = and without extra ;
    Code:
    ifThen(preTest == 'ESI', prePC = (startingScore/87)*100
    );
    ifThen(preTest == 'PSI', prePC = (startingScore/82)*100
    );
    ifThen(preTest == 'USI', prePC = (startingScore/99)*100
    );
    ifThen(preTest == 'PRA', prePC = (startingScore/92)*100
    );
    Last edited by victor; 08-16-2022, 07:19 AM.

    Comment


    • crmclients
      crmclients commented
      Editing a comment
      Works perfect! Thanks so much Victor!

  • #3
    I have a similar problem, the ifThen conditions work, but it picks up the last ifThen, no matter what was chosen. I have several ifThen conditions but even if I choose X, it will set the value of 3 (where it should be 1 according to the formula). How to prevent this behaviour?

    Code:
    ifThen(locationCopy == 'x', entity\setAttribute('locationRegistration', '1')
    );
    ifThen(locationCopy == 'y', entity\setAttribute('locationRegistration', '2')
    );
    ifThen(locationCopy == 'z', entity\setAttribute('locationRegistration', '3')
    );​​

    Comment


    • #4
      Found the error, the locationCopy field is an array, locationRegistration is a varchar, has the error

      Comment

      Working...
      X