I have to calculate years of working.

niveditakumari
Mega Sage

Hi @shivatmika_19

 

I have written code and added below code to calculate years. 

It is not working. 

Please find attached screenshot : 

 

niveditakumari_2-1740941280843.png

 

niveditakumari_1-1740941167146.png

 

niveditakumari_0-1740941098056.png

 

Please help me to correct that. 

 

Regards, 

Nivedita 

 

 

2 ACCEPTED SOLUTIONS

@niveditakumari 
Please use the following content: 

Congratulations on ${mail_script:yearsOfWorking} Amazing Years, ${first_name} ${last_name}

Dear ${first_name} ${last_name},

Today marks a special milestone for ${first_name} ${last_name}'s ${mail_script:yearsOfWorking}-year work anniversary at ACME South America! Over the years, ${first_name} ${last_name} has consistently contributed their qualities/skills to our team.

From leading successful projects in department Product Management to mentoring new team members, ${first_name} ${last_name} has been an invaluable part of our journey." Your commitment and hard work have made a lasting impact, and we're so grateful to have you as part of our ACME South America family.

Let's all take a moment to congratulate ${first_name} ${last_name} and celebrate their incredible journey with us. Here's to many more successful years together!

Thank you for being an inspiration and for all the contributions you've made. Happy Work Anniversary, ${first_name} ${last_name}!

Signature:

Aruna,

Human Resource Manager.

I believe I've addressed all of your questions. If you're satisfied with the solution, kindly click the thumbs up and accept my answer to close this thread.

 

 

 


Thanks & Best regards,
Medi

View solution in original post

@niveditakumari 

If you are using DateTime field please adjust the script as follow:

var hiringDate = current.u_hr_hire_date;
var hiringDateGd = new GlideDateTime(hiringDate);
var currentDateGd = new GlideDateTime();
var hiringYear = hiringDateGd.getYearUTC();
var currentYear = currentDateGd.getYearUTC();
var experience = currentYear - hiringYear;
template.print(experience);

Thanks & Best regards,
Medi

View solution in original post

29 REPLIES 29

Hi @Ankur Bawiskar

 

It is on sys_user table. 

We don't use any table in email script. 

 

Regards, 

Nivedita 

 

 

@niveditakumari 

so notification is on sys_user table.

Is that field also on sys_user?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi @Ankur Bawiskar

 

Yes my notification is on sys_user and field is on sys_user table. 

My notification is working as expected. 

 

Regards, 

Nivedita 

 

 

@niveditakumari 

for the record you are testing has some date in it?

Basically you want to find difference in years between 2 dates?

your line 15 should be updated as this as you are using wrong date object for current date.

var currentYear = currentDateGd.getYearNoTZ();

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi @Ankur Bawiskar

 

Thank you so much it worked for me. 

niveditakumari_2-1741173700459.png

 

I need to calculate and show that as per below screenshot : 

niveditakumari_0-1741173544541.png 

 

Can you please help me to achieve that. 

 

Regards, 

Nivedita