Update Related Records automatically using info from Linking modules
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 > Developer Space > Functions > + Create New Function.
- Select Automation as Function type and click Next.
- Provide a name for the function. Add a description(optional).
- Copy the code given below.
- Click Edit Arguments.
- Enter the name as dealId and select the type as Int.
- Enter the name as contId and select the type as Int.
- Click Save&Execute Script.
- Click Save.
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;
Adding to the workflow
- 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" in the "When do you want to execute this rule?".
- Select "Field Update" and click "Repeat this workflow whenever a record is edited".
- Select "Deal Owner" and click Next.
- Select the Condition as "All Records".
- Select the checkbox "Repeat this workflow whenever a record is edited." and Click Next.
- Choose "Function" from Instant Actions.
- Select the option "Function" (Created by users from your organization).
- Select the required custom function and click Configure.
- Click Save and Associate.
- Save the workflow.
Note:
- The Function is applicable only when you create Campaigns in CRM. More on that here.
- The above code works only for API V2.0 and not the previous version.
Found this useful? Try it out and let us know how it works! If you have questions, do not hesitate to ask! Share this with your team if you find it useful!