ifThen formula inside of record\create formula

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

    ifThen formula inside of record\create formula

    Hey everyone. Not sure anyone can assist me on this. I need to use a ifThen formula within the record\create. Below is what Im using. Anyone see where Im messing up on this? I've messed with this for hours but can't seem to have any luck.

    $invoiceId=record\create(
    'Invoice',
    'dateInvoiced', datetime\now(),
    'billToId', ownerId,
    'accountId', id,
    'preDiscountedAmount', fireDueCost,
    'grandTotalAmount', fireDueCost,

    'dueDate',ifThen(
    client.fireDuesNetTerms == '14 Days',
    entity\setAttribute('dueDate', datetime\addDays(dateInvoiced, 14))
    );



    ifThen(
    client.fireDuesNetTerms == '30 Days',
    entity\setAttribute('dueDate', datetime\addDays(dateInvoiced, 30))
    );



    ifThen(
    client.fireDuesNetTerms == '60 Days',
    entity\setAttribute('dueDate', datetime\addDays(dateInvoiced, 60))
    );


    ifThen(
    client.fireDuesNetTerms == '90 Days',
    entity\setAttribute('dueDate', datetime\addDays(dateInvoiced, 90))
    );,
    );

  • item
    Active Community Member
    • Mar 2017
    • 1476

    #2
    lol,
    if you can't do it in .. make it outside
    put your result to variable $dueDate..
    ifThen(
    client.fireDuesNetTerms == '90 Days',
    $dueDate = datetime\addDays(dateInvoiced, 90))
    );

    and then use it in your record/create( 'dueDate', $dueDate)

    ​​​​​​​

    If you could give the project a star on GitHub. EspoCrm believe our work truly deserves more recognition. Thanks.​

    Comment

    • dodom2
      Senior Member
      • Jan 2020
      • 198

      #3
      Thanks for the response. I haven't used Variables yet but if I understood you correctly it would be this?

      Comment


      • item
        item commented
        Editing a comment
        put the word/text and not print screen !
    • dodom2
      Senior Member
      • Jan 2020
      • 198

      #4
      $duedate=ifThen(
      client.fireDuesNetTerms == '14 Days',
      entity\setAttribute('dueDate', datetime\addDays(dateInvoiced, 14))
      );

      ifThen(
      client.fireDuesNetTerms == '30 Days',
      entity\setAttribute('dueDate', datetime\addDays(dateInvoiced, 30))
      );

      ifThen(
      client.fireDuesNetTerms == '60 Days',
      entity\setAttribute('dueDate', datetime\addDays(dateInvoiced, 60))
      );

      ifThen(
      client.fireDuesNetTerms == '90 Days',
      entity\setAttribute('dueDate', datetime\addDays(dateInvoiced, 90))
      );

      $invoiceId=record\create(
      'Invoice',
      'dateInvoiced', datetime\now(),
      'billToId', ownerId,
      'accountId', id,
      'preDiscountedAmount', fireDueCost,
      'grandTotalAmount', fireDueCost,
      'dueDate', $duedate,
      );

      Comment

      • item
        Active Community Member
        • Mar 2017
        • 1476

        #5
        $dueDate = '2022-12-25'; // put a default value or you are the only who know
        ifThen(
        client.fireDuesNetTerms == '14 Days',
        $dueDate = datetime\addDays(dateInvoiced, 14)
        );

        ifThen(
        client.fireDuesNetTerms == '30 Days',
        $dueDate= datetime\addDays(dateInvoiced, 30)
        );

        ifThen(
        client.fireDuesNetTerms == '60 Days',
        $dueDate= datetime\addDays(dateInvoiced, 60)
        );

        ifThen(
        client.fireDuesNetTerms == '90 Days',
        $dueDate= datetime\addDays(dateInvoiced, 90)
        );

        and in entity\create('dueDate', $dueDate)
        If you could give the project a star on GitHub. EspoCrm believe our work truly deserves more recognition. Thanks.​

        Comment

        • dodom2
          Senior Member
          • Jan 2020
          • 198

          #6
          Its not working

          $duedate=
          ifThen(
          client.fireDuesNetTerms == '14 Days',
          $duedate=datetime\addDays(datetime\now(), 14))
          );

          ifThen(
          client.fireDuesNetTerms == '30 Days',
          $duedate=datetime\addDays(datetime\now(), 30))
          );

          ifThen(
          client.fireDuesNetTerms == '60 Days',
          $duedate=datetime\addDays(datetime\now(), 60))
          );

          ifThen(
          client.fireDuesNetTerms == '90 Days',
          $duedate=datetime\addDays(datetime\now(), 90))
          );


          $invoiceId=record\create(
          'Invoice',
          'dateInvoiced', datetime\now(),
          'billToId', ownerId,
          'accountId', id,
          'preDiscountedAmount', fireDueCost,
          'grandTotalAmount', fireDueCost,
          'dueDate', $duedate,
          );

          Comment

          • item
            Active Community Member
            • Mar 2017
            • 1476

            #7
            Originally posted by dodom2
            Its not working

            $duedate=
            ifThen(
            client.fireDuesNetTerms == '14 Days',
            $duedate=datetime\addDays(datetime\now(), 14))
            );
            ifThen don't return anythink !!!

            your line is bad..must be simply so

            ifThen(
            client.fireDuesNetTerms == '14 Days',
            $duedate=datetime\addDays(datetime\now(), 14))
            );

            And follow camelCase ! (it's just for respect espoCRM)

            duedate => dueDate


            If you could give the project a star on GitHub. EspoCrm believe our work truly deserves more recognition. Thanks.​

            Comment

            • dodom2
              Senior Member
              • Jan 2020
              • 198

              #8
              Thank you for help still. You still taught me the purpose of the variable and so I appreciate you.

              Comment

              Working...