The follow code will help you Count the Open Opportunities connected to your Accounts.
You need to use Custom Function under setting then follow the steps below:
- Create a new field in the Accounts Module such a Open Deals. Use Number type.
- Check the API Name given by Zoho CRM for that field. This is under Settings, API, then switch to API Names and locate the module then field name. The API names will be displayed. Open Deals will properly be called Open_Deals but you need to always check.
- Create a Custom Function for the Deals Module. (Settings | Actions | Functions)
- Define a single argument accID and link to Account Id
- Paste the below code
resp = zoho.crm.getRelatedRecords("Deals","Accounts",accId.toLong());
total = 0;
for each rec in resp
{
stage = rec.get("Stage");
if(stage.notContains("Closed - Won") && stage.notContains("Closed - Lost") && stage.notContains("Cancelled"))
{
total = total + 1;
}
}
updateResp = zoho.crm.update("Accounts",accId.toLong(),{"Open_Deals":total});
info updateResp;
6. For the above, replace lost, cancelled and won with the variables that define your Deal as CLOSED, e.g. not open.
7. Replace Open_Deals with the API name of the field.
8. Create a Workflow and link the Custom Function to execute on Create and Edit, every time.
This can be now used in Reports on in list views.
Good Luck.