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
require_once('modules/AOS_Products/AOS_Products_sugar.php');
require_once('modules/AOS_Products/AOS_Products.php');
class updateProductQuantity
{
public $module = 'Cases';
public function updateQuantity($bean, $event, $arguments)
{
$GLOBALS['log']->error('updateQuantity Called');
$GLOBALS['log']->error($bean->part1_c);
$p = new AOS_Products();
$p->retrieve_by_string_fields(array('name' => $bean->part1_c ));
$GLOBALS['log']->error($p->id);
$GLOBALS['log']->error($p->quantity_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;
$productBean->save();
}
}
Another question
Is there a way to have a button in edit view of case module that would show up once a product is added. This button would let me add additional products.
I want to achieve something like this
Let’s say i have two fields as follows:
Product 1 : Test Product
Product 1 Quantity: 10
Then, i would like to have a button that would allow me to add Product 2, Product 3, …
Is this possible?