Welcome back everyone!
Business scenario
Each of us have our strengths and weaknesses. Someone skilled in sales might not necessarily be better in management. It goes to show that in order to successfully run an enterprise, you need an amalgamation of various different talents that work together. Marketing, Sales, Negotiation, Support, Development, etc. All of them have their roles cut out clearly.
As such, lets say there's a guy from the Sales team who takes care of the leads and converting them into deals. Now, that guy has a lot of work to do in converting the lead. Assigning tasks, events, scheduling calls, emails, cases, quotes, purchase orders, etc. He might have to lay the groundwork for the guy who takes care of the negotiation part after the lead is converted. The initial owner of the deal and all the related records with the deal is the Sales guy, but when converted into a deal, shouldn't the ownership change for all of the records? But guess what, changing the deal ownership doesn't change the rest.
But we do have a workaround as you've guessed, since we explained things this far. You can use a function to transfer the ownership for all of the records simultaneously. And this works best when the function is created within a Workflow rule, which can be set to trigger "This rule will be executed when the field Leads Owner is updated to meet the condition(if any)." And there you have it.
Getting started with the function
- Go to Setup > Automation > Workflow Rules.
- Click '+ Create Rule'.
- Select the Module for which this custom function has to be added and give it a name and a description(optional).
- Select "On a record action".
- Select "Field Update" and Select the checkbox "Repeat this workflow whenever a record is edited".
- Select "Deal Owner" and click Next.
- Select "All Records" for the Condition.
- Choose "Function" from Instant Actions.
- Click "+New Function".
- Select "Write your own".
- Give a name for the function and copy the code given below.
- Click On edit Arguments and choose 'Deal ID' and name it as 'dealId' and choose 'Deal Owner ID' and name it as 'dealownerid'
- Click on "Save and Associate".
- Save the workflow.
The Code
-----------------------------------------------------------------------------------------------------------------------
relatedcases = zoho.crm.getRelatedRecords("Cases", "Deals", input.dealId.toLong());
//info relatedcases;
for each ele in relatedcases
{
update = zoho.crm.update("Cases",ele.get("id"),{"Owner":input.dealownerid});
}
-----------------------------------------------------------------------------------------------------------------------
Note
- The code given above works only for V2 version of Zoho APIs. Please note that the code WILL NOT work for Version 1.0 APIs.
- Change the module name in the code from "Cases" to any other module you want.
Found this useful? Try it out and let me know how it works! If you have questions, do not hesitate to ask! Do check out other functions shared in this series here.
See you all next week with another interesting function. Ciao!