Custom Function: Updating the owner of the related cases when the potential owner is updated.

Custom Function: Updating the owner of the related cases when the potential owner is updated.

Scenario: Updating the owner of the related cases when the potential owner is updated. 

A potential in Zoho CRM can have several cases associated with it. If you wish to assign the potentials to a new user, you may also want to assign the associated cases to the new user.

Currently, when the owner of the potential is changed, ownership to the associated cases will not be changed.

You can achieve this by custom function and change the ownership for associated cases

Please follow these steps:

  1. Log in to Zoho CRM with administrative privileges.
  2. Click Setup > Automation > Workflow > Create Rule.
  3. In the New Rule page, choose Potentials module from the drop-down list and provide other rule details.
  4. Under Execute On, choose Create or Edit and then click Next.
  5. Specify the Rule Criteria. Choose the Potential Owner field in the first drop down. The rule will triggered only when a record meets the criteria mentioned here.
  6. In the Actions section, click on the Add button for Call Custom Functions.
  7. In the Configure Custom Function popup, click Write your own.
  8. Specify a name for the function.
  9. Build the Deluge Script based on the code given below.

Deluge Script:


void workflowspace.Change_Owner(string potentialId)//Getting PotentialID

  1. {

    potresp = zoho.crm.getRecordById("Potentials",input.potentialId.toLong());//Getting Potential Detail by using API

    potrespStr=potresp.toString();//Converting Potential response in to String

    potMap=potrespStr.toMap();//Converting String to Map

    smownerid=potMap.get("SMOWNERID");//Getting OwnerID from potential Map

    owner=potMap.get("Potential Owner");//Getting OwnerID from potential Map

    resp = zoho.crm.searchRecordsByPDC("Cases","potentialid",input.potentialId);//Getting Cases Related To That Potential for each rec in resp//

    {

    caseID=rec.get("CASEID");

    caseupresp = zoho.crm.updateRecord("Cases",caseID,{ "SMOWNERID" : smownerid, "Case Owner" : owner });//Upating owner of Each Cases Associated with that potential  

    }

    }

Note: This custom function can be used not just for the Potentials and the associated cases. However, you can modify the custom function for any other modules with parent-child relationship.

Please refer to the following link to know more about this feature:

https://www.zoho.com/crm/help/automation/custom-functions.html