Announcement

Collapse
No announcement yet.

Check if invoice already exist (workflow)

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

  • Check if invoice already exist (workflow)

    hello
    i create a workflow on sales of order and that create invoice after paid
    and i want to check if invoice was already created ?
    my desire workflow
    - start event on save my sale order
    - create an exclusive gatway
    - if invoice is already created go to end
    - if invoice doesn't exist continu my workflow to create invoice
    i didn't find how to test "if invoice exist"
    thanks

  • #2
    sorry to bump this but no way to check it easier ?

    Comment


    • #3
      sorry nobody have an idea ?

      Comment


      • #4
        A SalesOrder has many invoices so it will be difficult to know if an invoice is created unless if you have used a condition like createdAt and loop through the collection to check if an invoice is createdAt today then move otherwise move to create an invoice. If you share your bpmn i might be able to help.
        Rabii
        Web Dev | Freelancer

        Comment


        • yuri
          yuri commented
          Editing a comment
          Either to use record\findRelatedOne to check whether at least one invoice exists. Or to use a custom read-only field "isInvoiceCreated" that is set automatically to true by formula when an invoice is created.

      • #5
        Code:
        $count = entity\countRelated('invoices'); // invoices is link name
        $idsFiltered = record\findMany('Invoice', 100, 'createdAt', 'asc', 'salesOrderId=', id, 'status=', 'Paid'); // filtered invoice IDs
        $countFiltered = array\length($idsFiltered);
        
        output\printLine($count);
        output\printLine($idsFiltered);
        output\printLine($countFiltered);
        
        ifThen($countFiltered >= 1,
        output\printLine('Invoice exists');
        )
        You can do this through formula script, I put couple examples above.

        Output from formula sandbox:
        1
        ["65df31952687fba8d"]
        1
        Invoice exists​

        Comment

        Working...
        X