Create Events from Deals automatically

Business scenario:

A lot goes behind winning a deal. You need to qualify the deal, analyse client requirements, , make proposals, negotiate with the client, offer discounts to match competitor's proposals to finally closing it. Depending upon your line of business, you might have to create events to progress with the deal closure. Let me give you an example. After you offer a proposal and create a deal, prospects might need a demo or a hands-on session of your offering(s). Even if you customize your deal stages to include Demo/Hand-on as one of the stages, it'd be great if you include a related event tied to that deal stage. This function lets you create events automatically whenever you feel the need for it.

For instance, you could create a checkbox in the Deals module with the name "Needs Demo". And once that checkbox is selected, a workflow is triggered to set up an Event for the location, date, time, participants and host would be taken from the deal record.

Pre-requisites

  • Create a custom field named "Demo Date". This is for the code given below and it may vary depending on the need.
 

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. Click Save&Execute Script.
  8. Click Save.
 

The Code:


DealDetails = zoho.crm.getRecordById("Deals", input.dealId);
//info DealDetails;
startdate = ifnull(DealDetails.get("Contract_Start_Date"),"").toString("yyyy-MM-dd");
enddate = ifnull(DealDetails.get("Contract_End_Date"),"").toString("yyyy-MM-dd");
eventmap =map();
eventmap.put("Event_Title",ifnull(DealDetails.get("Deal_Name"),""));
eventmap.put("Who_Id",ifnull(DealDetails.get("Contact_Name"),"").get("id"));
eventmap.put("Owner",ifnull(DealDetails.get("Owner"),"").get("id"));
eventmap.put("What_Id",input.dealId);
eventmap.put("$se_module","Deals");
eventmap.put("Start_DateTime",startdate+"T09:00:00+05:30");
eventmap.put("End_DateTime",enddate+"T10:00:00+05:30");
create1 = zoho.crm.create("Events", eventmap);
info eventmap;
info create1;

 

Result of the workflow

 

Open activity created

 

Note:

  • You can modify the code to be able to create records in other modules from the deals module. Furthermore, you can mod it to create records from modules other than Deals.
  • When creating the workflow for the function, associate the 'dealId' argument to the Deal Id value.
  • 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