I'm creating a macro within our application to grab a date field, add a specific number of business days to it, and then set a new field to said date. I want account for weekends and holidays so it bypasses them. I wrote this with the understanding that I can nest IF ELSE statements, is this correct? (I'm a beginner)..
To explain my process, first it will get the date from the field. Then check if its null, if so then set null. If not, continue to check if the day is a holiday, then check again for a 2nd holiday. if 2 holidays in a row, add 2 days. if only 1 holiday, add 1 day. after, check if that date is now saturday or sunday and if so,append 1 or 2 days respectively. Lastly, set new date field to myDate.
//create variables for each extended field
var reviewDueBy = los.GetField("ExtendedFields.Appraisal_Review_Due_By");
var receivedDate = los.GetField("ExtendedFields.Appraisal_Received_Date_2");
var fullDate = Date();
var myDate = fullDate.toDateString();
function timestamp(){
fullDate.setDate(receivedDate); //this adds X amount of days
myDate.setDate(myDate.getDate() + 2);
//if receivedDate equals a holiday, then equals second holiday, add 2. else, add 1.
if (reviewDueBy === null || reviewDueBy === undefined) {
los.SetField(reviewDueBy, null);
} else {
if (/jan 1/i.test(myDate) || /may 25/i.test(myDate) || /jul 3/i.test(myDate) || /sep 7/i.test(myDate) || /oct 12/i.test(myDate) || /nov 26/i.test(myDate) || /dec 24/i.test(myDate)) {
if (/nov 27/i.test(myDate) || /dec 25/i.test(myDate)) {
myDate.setDate(myDate.getDate() + 2);
} else {
myDate.setDate(myDate.getDate() + 1);
}
}
}
//if date equals Sat, then add 2 days. if Sun, add 1.
if (/sat/i.test(myDate)) {
myDate.setDate(myDate.getDate() + 2);
} else if (/sun/i.test(myDate)) {
myDate.setDate(myDate.getDate() + 1);
}
timestamp();
los.SetField(reviewDueBy, myDate);
I had originally wrote this without it being nested, but neither this nor that worked.
Aucun commentaire:
Enregistrer un commentaire