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

thanks olaN,

but i used this method directly called script include function name in reports field  for upcoming bdays anniversary in dashboard and its working fine

 

function upAnniversary() {

    var upanniversary = [];

    var today = new GlideDate();

 

    var format = today.getByFormat('MM');

 

    var userGR = new GlideRecord('sys_user');

 

    userGR.addActiveQuery();

 

    userGR.addQuery('u_dobISNOTEMPTY');

 

    userGR.query();

 

    while (userGR.next()) {

 

        var DOJ = userGR.u_doj.toString();

 

        var anniversary = DOJ.split("-");

 

        DOJ = anniversary[1] + '-' + anniversary[2];

 

 

        if (format == anniversary[1]) {

            upanniversary.push(userGR.getValue('name'));

            //gs.print(userGR.name);

        }

    }

    return upanniversary;

}

 

 

Don't forget, you will also need to create a Flow or scheduled job, that runs yearly, and updates the next birthday date on all existing records.