Send Notification 5 business days before the Contract start date

Bhavana Reddy
Mega Guru

Hello Guys,

We need to send a Notification to the Business owners 5 Business days ( Mon to friday excluding weekends) before the Contract start date , can anyone please help me with the script part please

I tried a sample script in the background script but it doesnot work

var contractCi = new GlideRecord("contract_rel_ci");
contractCi.addNotNullQuery('ci_item');
contractCi.addEncodedQuery('contract.contract_model=e863bd7c1b7f6410138cfffe034bcb43^contract.ref_u_svo.u_ramp=true^contract.active=true^contract.startsISNOTEMPTY');
contractCi.addQuery('ci_item', '019fe1fadbfab01033b3560868961996'); // example record
contractCi.query();
while (contractCi.next()) {
var gdt = new GlideDateTime(contractCi.contract.starts);
var day = gdt.getDayOfWeekLocalTime();
if (day == 1 || day == 2 || day == 3 || day == 4 || day == 5) {
gdt.addDaysUTC(-7);
} else if (day == 6) {
gdt.addDaysUTC(-5);
} else if (day == 7) {
gdt.addDaysUTC(-6);
}


var dur=GlideDateTime.subtract(gdt, new GlideDateTime(contractCi.contract.starts));
var days = dur.getRoundedDayPart();
if(days== 7{

gs.eventQueue("ramp.reminder", contractCi, contractCi.contract.u_owner );
}

}

8 REPLIES 8

Hi,

 

This works when the start date is on weekdays but doesnt work when the start date is on weekend as the difference will not be equal to 7

I think 5 days should be subtracted on weekends instead of 6 or 7 because according to your req if the date falls on weekend then -5 days will take it to a weekday when you can send the notification. And the difference in days should be 5 for weekends like another else condition and check for 5 in case the date falls on weekend. 

I'm not sure it is right.. you know the req.. but this might work IMO

SumanthDosapati
Mega Sage
Mega Sage

Hi Bhavana,

 

This thread might help you.

 

Regards,

Sumanth

I already checked the above thread, They have written Business rule but in my case its scheduled job which runs everyday to check the condition

Can you please help here...