Last active
February 27, 2020 06:42
-
-
Save CubeYogi/f796aa90d07730a4b87d2aa0e79fec80 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Replace the module name with correct API name | |
product_module_name = "Products"; | |
deals_module_name = "Deals"; | |
//Replace the field API name correctly | |
product_unit_price_field_name = "Unit_Price"; | |
deals_amount_field_name = "Amount"; | |
//Fetches all product related to a deal from its related list | |
product_entries = zoho.crm.getRelatedRecords(product_module_name, deals_module_name, deal_id); | |
//Assign initial value of variable deal_amount as 0 | |
deal_amount = 0; | |
//Executes only when the product_entries is not empty | |
if (product_entries != null && product_entries.size() > 0) | |
{ | |
for each product in product_entries | |
{ | |
//Executes only when product unit price is not empty | |
if (product.get(product_unit_price_field_name) != null && product.get(product_unit_price_field_name) != 0) | |
{ | |
//get the unit price of each products | |
product_unit_price = product.get(product_unit_price_field_name); | |
} | |
//Calculate the total of products and stores the total in the variable deal_amount | |
deal_amount = deal_amount + product_unit_price; | |
} | |
} | |
//Create a map and add the calculated deal amount | |
update_deal_map = Map(); | |
update_deal_map.put(deals_amount_field_name, deal_amount); | |
//Update the deal record with map update deal | |
update_deal_entry = zoho.crm.updateRecord(deals_module_name, deal_id, update_deal_map); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment