I’ve created a custom Quantity field in Products Module to keep track of the stock for products. What i want to achieve is whenever a case is created and a product is used, i should be able to deduct it from the quantity field for that product. I tried creating a workflow but it only allows me to assign a value. How do i get the original value so that i can subtract from it?
Thanks for your reply. But i think the examples for calculated field only shows editing the fields for the workflow module we select. I want to run workflow on Cases module and subtract from a field in Products module. Let me know if it makes sense.
@pgr Thanks for your reply. I was able to implement what i need using logic hooks but the code is running everytime i make an update in the case. So even if don’t change anything the custom code executes and the product quantity keeps getting subtracted. Is there a way i can control it to run it only when a specific field is changed?
Here’s the custom code which runs using logic hook
public $module = 'Cases';
public function updateQuantity($bean, $event, $arguments)
$p = new AOS_Products();
$p->retrieve_by_string_fields(array('name' => $bean->part1_c ));
$p->quantity_c = $p->quantity_c - $bean->part1_quantity_c;
$productBean = BeanFactory::getBean('AOS_Products');
$productBean->id = $p->id;
$productBean->quantity_c = $p->quantity_c;