Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to autopopulate 'Due Date' field value depending on 'employee start date'

bhuvana7
Tera Contributor

Hello Everyone,

 

1) I need to Auto populate the 'Due Date' field value depending on employee's start date.

2) Due Date field I created it in 'HR Task' table and 'employee start date' field value is available in 'HR Profile' table.

3) So I created a Before-Insert, Update business rule in the 'HR Task Table' to get the value of 'employee start date' and to populate 'Due Date' value.

But whatever I created that is not working as expected, I am attaching the screenshots for reference. Please help me out with your suggestions/solutions.

Many Thanks in Advance!!

bhuvana7_0-1687876675229.pngbhuvana7_1-1687876706575.pngbhuvana7_2-1687876740956.pngbhuvana7_3-1687876777932.png

Kind Regards,

Bhuvana

1 ACCEPTED SOLUTION

Remove the current.update() line. I forgot you mentioned this is a BEFORE business rule.

Sable Vimes - CSA

View solution in original post

4 REPLIES 4

SVimes
Kilo Sage

Try this.

var date;
var par = current.parent.subject_person;
var gr = new GlideRecord('sn_hr_core_profile');
gr.addQuery('user', par);
gr.query();
while(gr.next()){
     date = new GlideDateTime(gr.getValue('employment_start_date'); //If this is a DATE ONLY field, change to date = new GlideDateTime(gr.getValue('employment_start_date') + " 00:00:00");
     date.addDays(7);
}
current.u_due_date = date; //If you need DATE ONLY, change to current.u_due_date = date.getDate();
current.update();
Sable Vimes - CSA

bhuvana7
Tera Contributor

Hello Claude,

 

I am getting these errors, can you please clarify this?

Error Message
1)java.sql.BatchUpdateException: (conn=3240220) Duplicate entry '7bce2abbdbe729d06697c59b13961940' for key 'PRIMARY'
Error Message
2)Invalid insert

bhuvana7_0-1687882036374.png

 

Remove the current.update() line. I forgot you mentioned this is a BEFORE business rule.

Sable Vimes - CSA

bhuvana7
Tera Contributor

Thank you Claude, working as expected.