Best answer

How do I auto-compute age from date of birth field in Pipedrive using Formatter by Zapier?

  • 11 September 2023
  • 11 replies
  • 144 views

Userlevel 1

Hi. We have a date of birth and age field in Pipedrive. We want to auto-compute the age based on the date of birth. I came across an article the might be solution using Formatter. Can someone share step by step guide? Ty

icon

Best answer by Troy Tessalone 11 September 2023, 16:22

View original

This post has been closed for comments. Please create a new post if you need help or have a question about this topic.

11 replies

Userlevel 7
Badge +14

Hi @MagneticAA 

Good question.

Try this Zap action: Code - JavaScript

// Convert the birthdate string to a Date object
let birthdate = new Date(inputData.birthdate);

// Get the current date
const currentDate = new Date();

// Calculate the age
const age = currentDate.getFullYear() - birthdate.getFullYear() - (currentDate.getMonth() < birthdate.getMonth() || (currentDate.getMonth() === birthdate.getMonth() && currentDate.getDate() < birthdate.getDate()) ? 1 : 0);

output = [{age, birthdate}];

 

Userlevel 1

Hi @Troy Tessalone Thank you. I’ll test it! 

Userlevel 1

Hi. @Troy Tessalone Seems to be working. But not reflecting in Pipedrive. Would appreciate any thoughts.

See below:
 

 

Userlevel 7
Badge +14

@MagneticAA 

You need to add a Step 3 to update the Person from Step 1.

 

Userlevel 1

Hi @Troy Tessalone Not sure which to set here. Can you please advise? Thank you so much. 

 



 

 

Userlevel 7
Badge +14

@MagneticAA 

The ID needs to be mapped from Step 1.

The screenshots shows the mapped dynamic variable is not a valid variable.

 

Userlevel 1

Hi @Troy Tessalone Apologies. I’m not really sure which field to choose or how to find the record from Step 1. Do you which specific field to find?
 

 

Userlevel 7
Badge +6

Hi there @MagneticAA,

I’m jumping in to see if I can help!

You will need the Person ID from the trigger, and map that as a custom value to the “Person” field in the Update Person step. Here’s what the Person ID data looks like:

470a31147b36fca16a4260c5b8516a4c.png
(view larger)

Additionally, it looks like you’re using an identical trigger (Updated Person) and action (Update Person) this might cause your Zap to loop infinitely. I suggest changing the trigger to the New Person trigger.

Hopefully, this helps! 😊

Userlevel 7
Badge +14

@MagneticAA 

Search for ID.

 

Userlevel 1

Thank you so much @Troy Tessalone It’s working now. 

Userlevel 7
Badge +6

Awesome! Glad to hear Troy was able to help you out @MagneticAA!

If you have any other questions, please don’t hesitate to reach out to the Community. We’re always happy to help! 😊