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:
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;

Comment