No announcement yet.

Updating integers in related-entities with formulas.

  • Filter
  • Time
  • Show
Clear All
new posts

  • Updating integers in related-entities with formulas.

    So, I'm trying to create an inventory system utilizing the formulas. I'm getting the hang of using these formulas. So first I'll paste my code:
    name = productName;
    $newAvailable = inStock - qtyToMove;
    $newReserve = inReserve + qtyToMove;
    ifThen(qtyToMove > 0 && product != null && status == 'Active', product.available = $newAvailable);
    ifThen(qtyToMove > 0 && product != null && status == 'Active', product.reserved = $newReserve);
    ifThen(itemType == 'Serialized', qtyToMove = 1);

    The first line works. The name is identical to the product selected.
    The next two variables were created because I had originally finished the next lines with , product.available = product.available - qtyToMove); and that didn't work, so I tried created a local variable and referencing a foreign entity. inStock and inReserve are foreign fields that reflect the product fields.
    So the four middle lines have no indication of working.
    The last line does work, so if it is like any other code processor, it doesn't bug out before the last line, but there is no return.
    Could you please advise at what might be wrong?

  • #2
    not sure, you can modify related entity with formula...
    for this is better to use hooks (you need afterSave)