ifThen or nested ifThenElse? Contacts Formula

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • crmclients
    Senior Member
    • Jul 2020
    • 254

    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;
    );
  • victor
    Active Community Member
    • Aug 2022
    • 727

    #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!
  • angelinasavchuk
    Junior Member
    • Feb 2023
    • 2

    #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

    • angelinasavchuk
      Junior Member
      • Feb 2023
      • 2

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

      Comment

      Working...