Creating a workflow rule

Creating a workflow rule

Hello!
We've created a function that copies data from a related Product to a related Deal.
We want to know is there a way how can we trigger this function when we add Product to a deal.
How we expect it will work:
we add a Product to a deal - data from Product get automatically copied to a Deal.
Custom function:
1. 
http://joxi.ru/bmo98GwCxMR0KA
2. 
productDetails = zoho.crm.getRecordById("Products",productId.toLong());
mp = Map();
mp.put("field31",ifnull(productDetails.get("field20"),""));
mp.put("field36",ifnull(productDetails.get("field21"),""));
mp.put("field24",ifnull(productDetails.get("field19"),""));
mp.put("field23",ifnull(productDetails.get("field12"),""));
mp.put("field18",ifnull(productDetails.get("field18"),""));
mp.put("field10",ifnull(productDetails.get("field3"),""));
mp.put("field25",ifnull(productDetails.get("field27"),""));
mp.put("field21",ifnull(productDetails.get("field26"),""));
update = zoho.crm.update("Deals",dealId.toLong(),mp);
info mp;
info update;

Thank you in advance.
EMERGENCY)