Custom Function : Updating Birth Date / Anniversary Date / Due by date

Custom Function : Updating Birth Date / Anniversary Date / Due by date

Scenario: Updating Birth Date / Anniversary Date / Due by date

You may want to send recurring newsletters to the customers. For example, greeting your customers on Birthdays or Anniversary Days or getting reminded of the next payment that you would receive from your customers.

 

The next birthday date or the next anniversary date or the next due by date can be automatically updated provided you edit and save the record once in between the two birthdays or two anniversary date, etc.

You can use this date to send the greetings or newsletters or alert the customers for payments.

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. 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.AnniversaryDate(int potID,string Anniversary_Date)

  1. {

    resp = zoho.crm.getRecordById("Potentials",input.potID);

    respStr=resp.toString();

    respMap=respStr.toMap();

    startDateStr=respMap.get("Closing Date");

    closeDate=startDateStr.toDate();

    modifiedTime=(respMap.get("Modified Time")).toDate();

    createdTime=(respMap.get("Created Time")).toDate();

    anniversaryDateStr=respMap.get("Anniversary Date");

    if(anniversaryDateStr  ==  null)

    {

    anniversaryDate=closeDate.addMonth(1);

    }

    else

    {

    anniversaryDate=anniversaryDateStr.toDate();

    modifyMonth=(modifiedTime.getMonth()).toString();

    anniversaryMonth=(anniversaryDate.getMonth()).toString();

    if(anniversaryDate.getYear()  <  modifiedTime.getYear())

    {

    anniversaryDate=anniversaryDate.addMonth(1);

    info "Year" + anniversaryDate;

    }

    else

    {

    if((anniversaryDate.getYear()  <=  modifiedTime.getYear())  &&  (anniversaryMonth.toDecimal()  <  modifyMonth.toDecimal()))

    {

    anniversaryDate=anniversaryDate.addMonth(1);

    info "Month" + anniversaryDate;

    }

    else

    {

    if(((anniversaryDate.getYear()  <=  modifiedTime.getYear())  &&  (anniversaryMonth.toDecimal()  <=  modifyMonth.toDecimal()))  &&  (anniversaryDate.getDay()  <  modifiedTime.getDay()))

    {

    anniversaryDate=anniversaryDate.addMonth(1);

    }

    }

    }

    }

    crupt = zoho.crm.updateRecord("Potentials",input.potID.toString(),{input.Anniversary_Date:anniversaryDate});

    }

Note: We have done this custom function for the anniversary date in the potentials module which will be calculated based on the Potential closed date. If you want this in a different module and for a different field, you need to change the module name and the field name in the custom function.


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

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