Scheduled job is not working for HR Profile

Priya14
Tera Contributor

Hi,

I have created a new field in the Hr profile which will stores the employee work experience based on employee start date. This needs to be achieved through schedule job. I have also scripted the code to implement this. But it is not working in HR Profile table.

 

 

var cur = new GlideDateTime(); 

 var gr = new GlideRecord('sn_hr_core_profile');

gr.addEncodedQuery();

gr.query();

while (gr.next()){

var start = gr.getValue('employment_start_date');    

var dur = new GlideDuration(GlideDateTime.subtract(start, cur));    

var inYears = dur.getDayPart() / 365;    

var Years = parseInt(inYears);

gr.setValue('u_work_exp', Years);

gr.update();

}

 

Is there any issue on the code?

why it is not working in HR Profile table. Kindly help with the solution.

 

Thanks in advance

 

 
 
1 ACCEPTED SOLUTION

abirakundu23
Mega Sage

Hi @Priya14 ,

Please try below code.

abirakundu23_0-1714113496792.png

Please mark helpful & accept answer if it's really worthy for you.

View solution in original post

6 REPLIES 6

Sandeep Rajput
Tera Patron
Tera Patron

@Priya14 This script should work for you.

 

 var cur = new GlideDateTime();
 var gr = new GlideRecord('sn_hr_core_profile');
 //gr.addEncodedQuery(); add your query here

 gr.query();

 while (gr.next()) {

     var start = new GlideDateTime(gr.getValue('employment_start_date'));

     var dur = new GlideDuration(GlideDateTime.subtract(start, cur));

     var inYears = dur.getDayPart() / 365;

     var Years = parseInt(inYears);

     gr.setValue('u_work_exp', Years);

     gr.update();

 }

 

In your script the issue was there at line number 9

var start = gr.getValue('employment_start_date');    

 This line returns a string value of date and in order to perform subtract on a date time you need to convert the string date to GlideDateTime. Hope this helps.

abirakundu23
Mega Sage

Hi @Priya14 ,

Please try below code.

abirakundu23_0-1714113496792.png

Please mark helpful & accept answer if it's really worthy for you.