I want set upcoming birthdays of users in dashboard

Abishek V
Tera Contributor

In existing user table i added date of birth for users and now i have to create dashboard for upcoming birthday list and every year it need to show how can i acheive this?

2 ACCEPTED SOLUTIONS

Sure thing!

Write a business rule, as below:

set-next-birthday-BR.png

 

And as script, write something like this:

(function executeRule(current, previous /*null when async*/) {

	var nextBirthday = new GlideDateTime(current.getValue('u_birth_date'));  // change field name to your custom field name
	while(nextBirthday.before(new GlideDateTime())){
		nextBirthday.addYears(1);
	}
	current.setValue('u_next_birthday', nextBirthday);  // change field name to your custom field name

})(current, previous);

View solution in original post

I prefer Flow designer over scheduled job, but you can go with either one.

No condition should be needed on the trigger, other than it should run yearly on the first day of the new year.

Adding a simple example below, using Flow designer.

set-next-birthday-Flow.png


Providing some explanation of some of the steps in the Flow below, first step 1

flow-details-step-1.png

 

Step 3

flow-details-step-3.png

 

Step 5

flow-details-step-5.png

View solution in original post

11 REPLIES 11

Abishek V
Tera Contributor

hi olaN ,

 

thanks for this, currently am working on option no 2 i acheived this calculation logic through client script but i want to do this in business rule could you help me?

 

Sure thing!

Write a business rule, as below:

set-next-birthday-BR.png

 

And as script, write something like this:

(function executeRule(current, previous /*null when async*/) {

	var nextBirthday = new GlideDateTime(current.getValue('u_birth_date'));  // change field name to your custom field name
	while(nextBirthday.before(new GlideDateTime())){
		nextBirthday.addYears(1);
	}
	current.setValue('u_next_birthday', nextBirthday);  // change field name to your custom field name

})(current, previous);

Abishek V
Tera Contributor

Thanks olaN, its working fine 

 and why we using this line - 

while(nextBirthday.before(new GlideDateTime()))}
 

  and what is the condition i want to give in scheduled job?

The while loop is there to make sure the correct date is set.

For example, if birthdate is 2018-03-01, then the logic will run as follows.

add another year to the variable, so it will become 2019-03-01, then do another compare in the while condition (the date is still less than (before) todays date (which is returned from new GlideDateTime()).

So the loop continues, and sets the variable to 2020-03-01, 2021-03-01, 2022-03-01, 2023-03-01, and finally 2024-03-01.

Then the condition of the while loop fails (because now the date is after today's date), and the date is set as next birthday date.

I prefer Flow designer over scheduled job, but you can go with either one.

No condition should be needed on the trigger, other than it should run yearly on the first day of the new year.

Adding a simple example below, using Flow designer.

set-next-birthday-Flow.png


Providing some explanation of some of the steps in the Flow below, first step 1

flow-details-step-1.png

 

Step 3

flow-details-step-3.png

 

Step 5

flow-details-step-5.png