How to execute a CRM custom function OnSave a product? I got this already
What I'm looking for is trying to fill the Unit Price field with the value of the Price 1 field converted to CAD
on my ClientScript side I got this
- product_ID = $Page.record_id;
- var response = ZDK.Apps.CRM.Functions.execute("Product_OnSave", { "product_ID": product_ID });
- console.log(response);
This is the error I got when click the save button
On my CRM custom function I got this
- //////////////////// Get currency exchange rate from USD ////////////////////
- response = invokeurl
- [
- url :"https://www.zohoapis.com/crm/v3/org/currencies"
- type :GET
- connection:"customfunction"
- ];
- usd_exchange_rate = response.get("currencies").get(1).get("exchange_rate").toDecimal();
- //////////////////// GET CURRTENT Product INFO ////////////////////
- getProduct = zoho.crm.getRecordById("Products",product_ID);
- Owner = getProduct.get("Owner").get("id");
- price_1 = getProduct.get("Price_1").toNumber();
- unit_price_cad = price_1 / usd_exchange_rate;
- unit_price_cad = unit_price_cad.truncate(2);
- //////////////////// UPDATE CURRTENT Product ////////////////////
- product_upd = Map();
- product_upd.put("Unit_Price",unit_price_cad);
- product_upd.put("Modified_By",Owner);
- product_upd_resp = zoho.crm.updateRecord("Products",product_ID.tolong(),product_upd);
- info product_upd_resp;
- return product_upd_resp;
This function itself works as I want.