dateDiff is not allowed in scoped applications, what is the alternate way of finding the difference between two "DATE" fields

Shraddha Madye
Giga Contributor

Hi All,

We have a requirement to modify the Priority of an HR Case (this becomes a scoped application) based on 2 catalog variables in the record producer.

Requirement :

"Effective Date" is today or in the past AND "Is Pay Changing" = "Yes", then the priority should change from moderate to high

My Record Producer's Script

var eff_date = producer.effective_date;
var diff = gs.dateDiff(eff_date, GlideDate(), true);
var answer = '';
var pay_answer = '';
if (diff >= 0) {
answer = 'true';
}else {
answer = 'false';
}
var pay_answer = '';
if (producer.is_pay_changing == 'Yes') {
pay_answer = 'true';
} else {
pay_answer = 'false';
}

if (answer == 'true' && pay_answer == 'true') {

current.priority = 2;
} else {
current.priority = 3;
}

I get an error saying dateDiff is not allowed in sn_hr_sp. Use GlideDateTime.subtract() instead. 

Can anyone assist me on this as our HR catalog is using a Date variable and GlideDateTime.subtract() is a Date/Time function.

1 REPLY 1

Joshton1
Tera Guru

Hello Shraddha,

 

You can use the below script this should work for the mentioned requirement.

---------------------------------

var timeNow = new GlideDateTime();
var eff_date = new GlideDateTime(producer.effective_date);

var dur = GlideDateTime.subtract(timeNow,eff_date);
var difference  = dur.getNumericValue();

var answer = difference<=86400000 ? true : false;  // 86400000 is numeric value of 1 day i.e 24 hours.
var pay_answer = producer.is_pay_changing == 'Yes' ? true : false ;
current.priority = answer == true && pay_answer == true ? 2:3;
-----------------------------------
 
Please note that since you are selecting date on the record producer form, the value picked up in effective date and parsed via Glide date time will default to 00:00:00 and calculate the difference. So the calculation is done from current hour to the selected date's 0th hour. 
 
Hope this helps. Let me know if this worked for you.
 
Regards,
Joshton