Announcement

Collapse
No announcement yet.

Trying to calcualate values after save

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

  • Trying to calcualate values after save

    Hi

    I am trying to sum up recurring items and one-off items in the Quote submodule. I think I am really close and actually thought it worked, but I have now realised, since I use the saved values as source, I need to save twice in order to actually use fresh values.
    I have added a recurring boolean to the Product that is used to determine if the item is recurring or one-off.

    Here is my script, I think the first line is the issue, here I would rather have the posted new data, than the already saved data:

    Code:
    $items = record\findRelatedMany('Quote', id, 'items', 1000);
    
    $recurringTotal = 0;
    $initialTotal = 0;
    
    $i = 0;
    while(
        $i < array\length($items),
        (
            $quoteitem_id = array\at($items, $i);
            output\printLine( $quoteitem_id );
    
            $name = record\attribute('QuoteItem', $quoteitem_id, 'name');
            output\printLine( $name );
    
            $amount = record\attribute('QuoteItem', $quoteitem_id, 'amount');
            output\printLine( $amount );
    
            $product_id = record\findRelatedOne('QuoteItem', $quoteitem_id, 'product');
            output\printLine( $product_id );
    
            $recurring = record\attribute('Product', $product_id, 'recurring');
            output\printLine( $recurring );
    
            ifThenElse(
                $recurring,
                $recurringTotal = $recurringTotal + $amount,
                $initialTotal = $initialTotal + $amount
            );
    
    
            $amount = item.amount;
            $sum = $sum + $amount;
            $i = $i + 1;
        )
    );
    
    
    output\printLine( $recurringTotal );
    output\printLine( $initialTotal );
    
    amountRecurring = $recurringTotal;
    amountInitial = $initialTotal;
    Last edited by deadlock; 09-28-2022, 04:21 PM.

  • #2
    Please use code tags and reduce the example to the minimum amount of code that reproduces the issue. It's too hard read and too much to debug by inspection.

    Comment


    • #3
      bandtank I was looking for that button, but now I found it. I think the main issue is in the first row, here I receive an empty list at the first save. The other rows is just to see the whole picture what I am trying to do.

      Comment

      Working...
      X