Skip to main content

Recurring customer greetings

In this article, we'll show how to add your customers' birth dates automatically, eliminating the need for any extra action from managers.

This step-by-step guide explains how to set up recurring automation for birthday greetings or to create reminders. The process involves automatically recalculating the birthday date for the current or following year and saving it in a separate field.

Setting up fields in a folder

To begin with, you need to create three new fields in your folder:

  • Date of Birth – a date field where the date of birth is entered.

  • Technical field "Birthday" – the updated date of the next birthday will be automatically recorded here.

  • Record ID – create this as a separate single-line text field and designate it as the field for duplicate detection.

Configuring Google Apps Script

The Google Apps Script is responsible for the calculations: it checks whether the birthday has already passed this year and, if necessary, moves it to the following year.

  • Open the script editor and copy the following code into it:

function doPost(e) {
try {
var data = JSON.parse(e.postData.contents);
var recordId = data.id;
var birthDateStr = data.birthday;

var parts = birthDateStr.split('/');
var day = parseInt(parts[0], 10);
var month = parseInt(parts[1], 10) - 1;

var today = new Date();
// Встановлюємо сьогодні на початок дня для порівняння
var comparisonToday = new Date(today.getFullYear(), today.getMonth(), today.getDate(), 0, 0, 0);

var currentYear = today.getFullYear();

// Створюємо дату, встановлюючи 12 годин дня (полудень) замість півночі
var targetDate = new Date(currentYear, month, day, 12, 0, 0);

// Якщо ця дата в полудень вже пройшла сьогодні
if (targetDate < comparisonToday) {
targetDate.setFullYear(currentYear + 1);
}

// Форматуємо, використовуючи явний часовий пояс "GMT+3" (Київ влітку) або "GMT+2"
// Найкраще використовувати Session.getScriptTimeZone()
var updatedDateStr = Utilities.formatDate(targetDate, Session.getScriptTimeZone(), "dd/MM/yyyy");


var url = "https://nethunt.com/service/automation/hooks/69d026741f24de2bb193829e";
var payload = {
id: recordId,
updated_birthday: updatedDateStr
};


UrlFetchApp.fetch(url, {
"method": "post",
"contentType": "application/json",
"payload": JSON.stringify(payload)
});


return ContentService.createTextOutput(JSON.stringify({
"status": "success",
"returned": updatedDateStr
}))
.setMimeType(ContentService.MimeType.JSON);


} catch (error) {
return ContentService.createTextOutput(JSON.stringify({"status": "error", "message": error.toString()}))
.setMimeType(ContentService.MimeType.JSON);
}
}

💡Please note: You will need to replace the link in the script code with the current webhook for your CRM:

  • Publish the script by clicking: ‘Deploy’ → ‘New deployment’.

  • Select the ‘Web app’ type:

  • Fill in the fields and click "Deploy":

  • Authorize the access if the tool asks you to and copy the link to the web app:

Configuring the first workflow (Data transmission)

This automation will pass the original date to Google Script.

  • Trigger: The ‘Birthday’ field is filled in.

  • Action 1 "Update a record": Map the system Record ID field (marked with the NetHunt icon) to the newly created single-line field called "Record ID:

  • Action 2 "Make an API call": Paste the copied link to the web application into the URL field in the API call settings.

Add the API call details, where:

  • Select the request type – POST

  • The URL is the webhook taken from your Google Script to which you want to send the information:

https://script.google.com/macros/s/yourlink/exec
  • JSON – data to be sent using the JavaScript Object Notation format:

The whole workflow will look like this:

Configuring the second workflow (Webhook and data reception)

This automation takes the calculated date from the script and stores it in a technical field.

  • Trigger: Create a Webhook trigger. Copy its link and paste it into your Google Script code. Send a test request to the webhook so that it receives the variables (id and updated date). Be sure to specify the date format:

  • Create a record in your folder. Match the value returned by the Google Script with the field you have defined as the duplicate identifier (your ‘Record ID’ field):

  • Update a record. In this step, enter the calculated date into the technical field "Birthday" so that it can be updated every time a birthday occurs:

The whole workflow will look like this:

Configuring the third workflow (Launching recurring greetings)

Once the technical "Birthday" Field has been automatically updated, you can create a final recurring automation for a birthday greeting or reminder. This will be based specifically on this technical field, ensuring that the action takes place every year on the correct date.

Trigger: Field value changed: The automation is triggered whenever a new date appears in the ‘Technical Birthday’ field. As the script automatically resets the date to the following year once the cycle is complete, this process becomes infinite.

Branch distribution: To enable the system to perform different actions within a single workflow, the ‘Split into 3 branches’ logic step is used.

Branch A: Main customer greeting. This branch is responsible for communication on the day of the holiday itself.

  • Wait for the date: The system pauses the action until the date specified in the ‘Date of Birth’ field, specifically at 10:00 am (you can specify your own time).

  • Send an email: A festive ‘Congratulations’ email is sent to the customer.

  • Update the record: The first update requires clearing the ‘Birthday’ field. The final steps in this branch are designed to update the data in the client’s record and trigger the script to run again to update the date for the following year. We specify the current date and shift it by one year.

Branch B: Advance Reminder. This branch is required for internal team preparation:

  • Wait for the date: The system waits until the ‘Birthday’ date minus 1 day (or your specified value).

  • Create a task: The task is created for the responsible manager to prepare the email content.

Branch B: Change Monitoring

  • Wait for update: This branch monitors the ‘Date of Birth’ field (the main field filled in by the manager).

  • End workflow: If the manager manually changes the main date of birth, this specific automation session is halted to avoid conflicts and to wait for new calculations from the script.

Overview of the automation:


Haven’t found the answers you’re looking for? Ask our User's Community.

Did this answer your question?