Auto Populating Amount in Deal from Products Selected

Auto Populating Amount in Deal from Products Selected

I am trying to use below code found in a Zoho blog to auto populate an amount field in a Deal




  1. products = zoho.crm.getRelatedRecords("Products", "Deals", potId.toLong());

  2. unitprice = 0.0;
  3. for each product in products
  4. {
  5. unit = ifnull(product.get("Unit_Price"),"0.0").toDecimal();
  6. unitprice = unitprice + unit;
  7. }
  8. mp = Map();
  9. mp.put("Amount",unitprice);
  10. update = zoho.crm.updateRecord("Deals",potId.toLong(),mp);
  11. info mp;
  12. info update;
The function executes but doesn't find a product list, console output below

  1. {"Amount":0.0}
  2. {"Modified_Time":"2023-05-26T00:20:17+01:00","Modified_By":{"name":"Denise Flitcroft","id":"584257000000376001"},"Created_Time":"2023-05-25T23:59:17+01:00","id":"584257000000548959","Created_By":{"name":"Denise Flitcroft","id":"584257000000376001"}}
  3. Function executed successfully

Any idea where I'm going wrong?