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:

  1. Go to Setup > Developer Space > Functions > + Create New Function.
  2. Select Automation as Function type and click Next.
  3. Provide a name for the function. Add a description(optional).
  4. Copy the code given below.
  5. Click Edit Arguments.
  6. Enter the name as dealId and select the type as Int.
  7. Enter the name as contId and select the type as Int.
  8. Click Save&Execute Script.
  9. 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

  1. Go to Setup > Automation > Workflow Rules.
  2. Click '+ Create Rule'.
  3. Select the Module for which this custom function has to be added and give it a name and a description(optional).
  4. Select "On a record action" in the "When do you want to execute this rule?".
  5. Select "Field Update" and click "Repeat this workflow whenever a record is edited".
  6. Select "Deal Owner" and click Next.
  7. Select the Condition as "All Records".
  8. Select the checkbox "Repeat this workflow whenever a record is edited." and Click Next.
  9. Choose "Function" from Instant Actions.
  10. Select the option "Function" (Created by users from your organization).
  11. Select the required custom function and click Configure.
  12. Click Save and Associate.
  13. 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!

Return to Tips