Welcome back everyone!
Last week's function was about scheduling calls to records. This week, it's going to be about updating a record in one module with information from the linking modules, when two different records are linked.
Linking Modules
Multi-select lookup fields help create many-to-many relationships between records across modules. Linking Modules help facilitate this records association across modules. The records in the Linking Module contains info from the two 'linked' records. More on that here.
Business scenario
The standard sales process takes a linear approach. It starts with creation of leads followed by conversion to contacts and creation of deals. Depending upon your sales strategy, you can also have ad hoc processes. Campaigns, for instance, can be used to run either time bound sale promotions for existing customers or attract new clients.
Say you run a season ending promotional Campaign and one of your existing customers expressed interest for the same. As the customer already exists as a Contact in CRM, the next logical step is to create a Deal record from the Contact. It helps to make contextual follow-ups if the deal records track the relevant campaign names. Manually mapping them using a lookup field can be quite taxing. The Function I'm sharing this week cuts the manual work and tracks the campaign name automatically in the deal records.
When a Campaign targeted at existing customers is run, the relevant Contacts are associated with it. The Function pulls up the information from the Linking Module, containing the Contact and Campaign details and updates the Campaign name in the Deal Record.
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 "Create".
- 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'.
- Also add another argument. Choose 'Contact ID' and name it 'contId'.
- Click on "Save and Associate".
- Save the workflow.
The Code
-----------------------------------------------------------------------------------------------------------------------
linkingdata=zoho.crm.searchRecords("Contact_X_Campaigns", "(Multi_Select_Lookup_1:equals:"+input.campaignname+")");
//info linkingdata;
for each campaign in linkingdata
{
contId=campaign.get("Testing_Lookup").get("id");
}
info contId;
mp=map();
mp.put("Contact_Name",contId);
update=zoho.crm.update("Deals", dealId, mp);
info update;
-----------------------------------------------------------------------------------------------------------------------
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.
- The Function is applicable only when you create Campaigns in CRM. More on that here.
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!