Fourmula Help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dodom2
    Senior Member
    • Jan 2020
    • 198

    Fourmula Help

    Hello My Fellow Espo Peeps.

    I create a "Payment" entity to receive payments on invoices. I then created a One-to-Many relationship from invoices to payments. I then added a currency field in invoice module called " Amount Received". Now having that said I would like to SUM the field "Payment Amount Received" in the "Payment" module for all related payments. I would then like the result to be added in the "Amount Received" field in the invoice module. I'm NOT using any filter at this moment as Im just testing. Below is my formula which is based on the documentation here >>https://www.espocrm.com/documentation/administration/formula/<<

    amountReceived=entity\sumRelated('Payment', 'paymentAmountReceived')

    Can anyone see anything wrong with this formula as its not calculating? (Below is screenshots of all related modules)

    Entity Manager Invoice Relationship Screenshot: https://prnt.sc/qqdv6w
    Entity Manager Invoice Fields Screenshot: https://prnt.sc/qqdvv2
    Entity Manager Payment Fields Screenshot: https://prnt.sc/qqdwb9
    Entity Manager Payment Relationships Screenshot: https://prnt.sc/qqdwb9
    Invoice Screen: https://prnt.sc/qqdy3b
  • rodrigocoelho
    Active Community Member
    • Jun 2016
    • 296

    #2
    Originally posted by dodom2
    Hello My Fellow Espo Peeps.

    I create a "Payment" entity to receive payments on invoices. I then created a One-to-Many relationship from invoices to payments. I then added a currency field in invoice module called " Amount Received". Now having that said I would like to SUM the field "Payment Amount Received" in the "Payment" module for all related payments. I would then like the result to be added in the "Amount Received" field in the invoice module. I'm NOT using any filter at this moment as Im just testing. Below is my formula which is based on the documentation here >>https://www.espocrm.com/documentation/administration/formula/<<

    amountReceived=entity\sumRelated('Payment', 'paymentAmountReceived')

    Can anyone see anything wrong with this formula as its not calculating? (Below is screenshots of all related modules)

    Entity Manager Invoice Relationship Screenshot: https://prnt.sc/qqdv6w
    Entity Manager Invoice Fields Screenshot: https://prnt.sc/qqdvv2
    Entity Manager Payment Fields Screenshot: https://prnt.sc/qqdwb9
    Entity Manager Payment Relationships Screenshot: https://prnt.sc/qqdwb9
    Invoice Screen: https://prnt.sc/qqdy3b
    Try amountReceived=entity\sumRelated('payment', 'paymentAmountReceived');

    Comment

    • dodom2
      Senior Member
      • Jan 2020
      • 198

      #3
      Sorry the below did not work either

      Try amountReceived=entity\sumRelated('payment', 'paymentAmountReceived');


      Comment

      • rodrigocoelho
        Active Community Member
        • Jun 2016
        • 296

        #4
        Originally posted by dodom2
        Sorry the below did not work either

        Try amountReceived=entity\sumRelated('payment', 'paymentAmountReceived');

        Post the workflow screen...

        Comment


        • dodom2
          dodom2 commented
          Editing a comment
          Its a custom script in the formula section but here it is>>> https://prnt.sc/qqhlxy<<<
      • rodrigocoelho
        Active Community Member
        • Jun 2016
        • 296

        #5
        It is missing the ; on the end of the line ...

        Comment

      • esforim
        Active Community Member
        • Jan 2020
        • 2206

        #6
        Look goods! Look like you just create a "Receipt" system, it one of the thing that I will be needing to do in the future as our client want receipts which is just a PDF printout of the Payments entity you create.

        Comment

        • Maximus
          Senior Member
          • Nov 2018
          • 2731

          #7
          Hello,
          You should use 'payments' instead of 'Payment' in the formula (e.g. amountReceived=entity\sumRelated('payments', 'paymentAmountReceived')). 'Payment' is the entity name but 'payments' is the name of a link to this entity in the relationship between Invoice and Payment.

          Comment

        • rodrigocoelho
          Active Community Member
          • Jun 2016
          • 296

          #8
          Are you sure it is triggering right the workflow? Did you see the LOG window of the workflow?

          Comment

        • dodom2
          Senior Member
          • Jan 2020
          • 198

          #9
          For everyone that has offered their help here. . . this is what ended up working:
          amountReceived = entity\sumRelated('payments', 'paymentAmountReceivedConverted'); amountReceivedCurrency = 'USD';

          Comment

          Working...