How to set Due Date on Survey from a field on the HR Lifecycle Event table

nborowiak
Tera Contributor

Hi all,

 

I was hoping you all could help me with a requirement I've been given by the business. We creating an Exit Interview process and in this process there is a field that sits on the sn_hr_le_case table called u_employees_last_working_day. Currently, there is a trigger condition for a survey that is generated when a Lifecycle case is created, and I also built out a business rule so that whenever a new Lifecycle case is created with various conditions, that survey will then get referenced to the Survey field that sits on the Lifecycle case.

 

What we are hoping to do here is we would like to have the Due date field from the Survey/Assessment to dynamically grab the Employee's last working day and then add 5 days to it and then have that new date be the updated Due date on the Survey/Assessment. I've managed to get it to work but it will only update the time to today instead of refencing the u_employees_last_working_day date. 

 

See screenshot for clarity purposes.

 

Thanks in advance!

1 ACCEPTED SOLUTION

Hi @nborowiak 

Use below. It will work.tested from my PDI

 

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

    // Add your code here
    var gr = new GlideRecord("sn_hr_le_case");
    gr.addQuery("sys_id", current.trigger_id);
    gr.query();
    if (gr.next()) {
var gdt = new GlideDate();
gdt.setValue(gr.u_employees_last_working_day);
gdt.addDays(5);
var days5 = gdt.getByFormat("dd-MM-yyyy");

        current.due_date = days5;  //field name from sn_hr_le_case
    }

})(current, previous);

 


Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy

View solution in original post

7 REPLIES 7

Gunjan Kiratkar
Kilo Patron
Kilo Patron

Hi @nborowiak ,

You can try below BR

GunjanKiratkar_0-1668699411055.png

 

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

    // Add your code here
    var gr = new GlideRecord("sn_hr_core_case");
    gr.addQuery("sys_id", current.task);
    gr.query();
    if (gr.next()) {
        current.due_date = gr.your_field_backend_name;  //replace your hr case field name
    }


})(current, previous);

Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy

Hi @Gunjan Kiratkar ,

 

I attempted to use your business rule but it failed to update the field.

 

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

// Add your code here
var gr = new GlideRecord("sn_hr_le_case");
gr.addQuery("sys_id", current.number);
gr.query();
if (gr.next()) {
current.due_date = gr.u_employees_last_working_day; //replaced with my field from the sn_hr_le_case
}


})(current, previous);

 

sorry typo in HR case table name 

Try below BR

 

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

// Add your code here
var gr = new GlideRecord("sn_hr_core_case");
gr.addQuery("sys_id", current.number);
gr.query();
if (gr.next()) {
current.due_date = gr.u_employees_last_working_day; //replaced with my field from the sn_hr_le_case
}


})(current, previous);

 


Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy

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

    // Add your code here
    var gr = new GlideRecord("sn_hr_le_case");
    gr.addQuery("sys_id", current.trigger_id);
    gr.query();
    if (gr.next()) {
        current.due_date = gd;  //field name from sn_hr_le_case
    }


})(current, previous);

I had to change line 5 from gr.addQuery("sys_id", current.number);

to  gr.addQuery("sys_id", current.trigger_id);

 

It is now populating the due date field but I now need to add 5 days to it.