Announcement

Collapse
No announcement yet.

How Does ifThenElse formula work?

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

  • How Does ifThenElse formula work?

    Can someone help me understand this formula?

    For example I'm calculating a balance.

    I have

    Status field with the picklist options of "New" and "Reconciled".

    These fields are based off of another field called "Reconciled Balance". When this field = 0.00 then it should change the status field to "Reconciled" however when this field is not = to 0.00 it should change the status field to "New". Any help would be appreciated.


    ifThenElse(CONDITION, CONSEQUENT, ALTERNATIVE)


  • #2
    Code:
    ifThenElse(
             reconciledBalance == 0,
             entity\setAttribute('status', 'reconciled'),
             entity\setAttribute('status', 'new')
    );

    Comment


    • esforim
      esforim commented
      Editing a comment
      Look like you becoming pro at formula.

    • dodom2
      dodom2 commented
      Editing a comment
      esforim I'm learning alot for sure!

    • item
      item commented
      Editing a comment
      @espcrm
      excellent .. since 2 day i smile

      @shalmaxb
      congratulation

  • #3
    thanks shalmaxb! That works like a charm my friend!

    Comment


    • #4
      Hi shalmaxb .

      Would you be able to help with this formula?

      ifThenElse(
      transactionType == Deposit,
      entity\setAttribute('reconciledamount', entity\sumRelated('expenses', 'grandTotalAmountConverted');
      entity\setAttribute('reconciledamount', entity\sumRelated('deposits', 'depositGrandTotal');
      );

      Comment


      • #5
        Hi,
        on first glance I think, you cannot put one function as argument into another in this nested form. You should untangle it.

        Code:
        ifThenElse(
        transactionType == Deposit,
        entity\setAttribute('reconciledamount', HERE IS MISSING THE VALUE),  <- Then command
        Code:
        entity\sumRelated('expenses', 'grandTotalAmountConverted');<- Else command
        Code:
        entity\setAttribute('reconciledamount', HERE IS MISSING THE VALUE)  <- this would be a second command
        Code:
        entity\sumRelated('deposits', 'depositGrandTotal');<- no semikolon here
        );

        Are you trying to mix two IfThenElse? It is not clear, what you want to achieve.
        Send the field names and what you do want to achieve.

        Comment


        • #6
          Sorry let me provide more detail.

          So I have a drop down field called "Transaction Type" with these 2 options "Expense" & "Deposit"

          If "Transaction Type" = "Deposit" then it should sum the "depositGrandTotal" field from the "deposits" entity
          If "Transaction Type" = "Expense" then it should sum the "grandTotalAmountConverted" field from the "expenses" entity.

          I currently have 2 separate workflows setup but would love to consolidate this into one workflow for the sake of organizing.

          Hopefully this helps!

          Comment


          • #7
            Ok,

            Code:
            ifThenElse(
            transactionType == 'Deposit',
            entity\sumRelated('deposits', 'depositGrandTotal'),
            entity\sumRelated('expenses', 'grandTotalAmountConverted')
            );
            For the Else you don`t need to declare the condition "expenses", because besides of deposits you only have this one more possibility and so it it is obvious, if it is not deposits, it must be expenses.
            If it does not work, look, if you have the right link field (the first value)

            Comment


            • #8
              Perfect! Now can we do this with the

              record\unrelate(ENTITY_TYPE, ID, LINK, FOREIGN_ID)

              formula as well? For example if transaction type = Deposit then Id want to unrelate any records in the "expense" field and vice-versa if transaction type = expense then I'd want to unrelate any records in the deposit field.

              Make sense?

              Comment


              • #9
                Hi, we can try. I guess the names of your entities ar "expenses" and "deposits".


                Code:
                ifThenElse( transactionType == 'Deposit',
                entity\sumRelated('deposits', 'depositGrandTotal');
                record\unrelate('expenses', expensesId, 'deposits', depositsId),
                entity\sumRelated('expenses', 'grandTotalAmountConverted');
                record\unrelate('deposits', depositsId, 'expenses', expensesId)
                );
                I took the former formula and extended it. So you have two Then commands and two Else commands. Watch out the commas ans semicolons, and the names of links and entities ( I had to guess a bit). I hope this works.

                Comment


                • #10
                  See I have a entity called "bankTransaction" which has 2 relate fields in it. One is "expenses" and one is "deposits". The transaction type field in the bank transaction field = "Deposit" then it should unrelate the data in "expenses" relate field. Having this said Im confused on why we're putting anything related to deposits here (see screenshot).

                  Comment


                  • #11
                    ok, I did not get, because you wrote, that you want to "unrelate expenses and vice-versa"
                    Let`s see, how to do that.

                    With which entity the two fields in bankTransaction are related?

                    Comment


                    • #12
                      Sorry about that! It can be a bit confusing to explain.

                      Entities are Deposits and Expenses which are related to "Bank Transactions"

                      Comment


                      • #13
                        ok, then I think it is this way:


                        Code:
                        ifThenElse(
                        transactionType == 'Deposit',
                        entity\sumRelated('deposits', 'depositGrandTotal');
                        record\unrelate('bankTransactions', bankTransactionsId, 'expenses', expensesId),
                        entity\sumRelated('expenses', 'grandTotalAmountConverted');
                        record\unrelate('bankTransactions', bankTransactionsId, 'deposits', depositsId)
                        );
                        What does it do:
                        1. If the transactionType is Deposit it sums deposits to depositGrandTotal and
                        2. it unrelates expenses in bankTransactions

                        If it is not Deposit (Else) it
                        1. sums expenses to grandTotalAmountConverted and
                        2. unrelates deposits from bankTransactions


                        I am not sure, if it is right, but we can try.

                        Comment


                        • #14
                          Hello,

                          I am new here but have a similar challenge for which I require assistance.

                          I have two entity namely Contact and Event with n:n relationship. Both entities have the following similar fields (street, city, section, district, region)

                          The event entity has a boolean field (sameAsContact)

                          I want a formula that will copy the content of the street, city, section, district and region from contact to event when the boolean field is set to TRUE​

                          Comment


                          • rabii
                            rabii commented
                            Editing a comment
                            you can use formula however because your n:n relationship it will be hard to specify which event to update, e.g a contact who is linked to 3 events then do you want to update all 3 events or just one of them?

                        • #15
                          ok, I did not get, because you wrote, that you want to "unrelate expenses and vice-versa"
                          Let`s see, how to do that.​
                          TeaTV is free to use android app which let's you watch movies and TV shows online for free. TeaTV is easy to use. Download TeaTV APK now.

                          https://hellodear.in

                          Last edited by xeamcopz; 03-02-2023, 12:55 PM.

                          Comment

                          Working...
                          X