PDA

View Full Version : Setting a turnaround level based on mail drop date?


brians
February 19th, 2013, 03:23 PM
Looking for assistance in creating a rule that will populate a field with a turnaround level based on input from the user into a Mail Drop Date field. Example: If the user chooses a mail drop date of Monday, February 25th, 2013 and today is Friday, February 22, 2013 the rule will set the turnaround field to Express 2 Business Days.

Rush 2 Business Days
Mail Drop Date <= 2 Business Days from Today

Express 3 Business Days
Mail Drop Date <= 3 Business Days from Today and > 2 Business Days

Standard 5 Business Days
Mail Drop Date >= 5 Business Days from Today

Since the input from the user can be controlled by the calendar function in Marcom I can set this to whatever format is easiest to code.

Thanks in advance for any help you can provide.

esmith
February 20th, 2013, 05:34 AM
Google is your friend:
var dDate1 = Today();
var dDate2 = DateFromString("2/25/2013"); //(Field("MailDropDate"));
var iWeeks, iDateDiff, iAdjust = 0;
var result = '';

// error code if dates transposed
if (dDate2 < dDate1) return "Your drop date occurs in the past!";

var iWeekday1 = dDate1.getDay();
var iWeekday2 = dDate2.getDay();

// change Sunday from 0 to 7
iWeekday1 = (iWeekday1 == 0) ? 7 : iWeekday1;
iWeekday2 = (iWeekday2 == 0) ? 7 : iWeekday2;

// adjustment if both days on weekend
if ((iWeekday1 > 5) && (iWeekday2 > 5)) iAdjust = 1;

// only count weekdays
iWeekday1 = (iWeekday1 > 5) ? 5 : iWeekday1;
iWeekday2 = (iWeekday2 > 5) ? 5 : iWeekday2;

// calculate difference in weeks (1000mS * 60sec * 60min * 24hrs * 7 days = 604800000)
iWeeks = Math.floor((dDate2.getTime() - dDate1.getTime()) / 604800000)

if (iWeekday1 <= iWeekday2) {
iDateDiff = (iWeeks * 5) + (iWeekday2 - iWeekday1)
} else {
iDateDiff = ((iWeeks + 1) * 5) - (iWeekday1 - iWeekday2)
}

// take into account both days on weekend
iDateDiff -= iAdjust;

// add 1 because dates are inclusive
//iDateDiff = iDateDiff + 1;

// determine correct turnaround
if (iDateDiff <= 2) result = 'Rush 2 Business Days';
else if (iDateDiff >= 5) result = 'Standard 5 Business Days';
else result = 'Express 3 Business Days';

return result;
Note that I commented out the "inclusive day" since I would think that "today" would not be factored in when determining turnaround time, especially if order is placed end of day.

brians
February 20th, 2013, 09:26 AM
This works perfectly in that it returns the value I'm look for however I'm not sure how I can now apply a price to the value in Marcom. My goal was to have the result of this rule populate a field that could then have a dynamic price attached. Is it possible to have a rule change the data and therefore make it visible to the intelligent forms?

esmith
February 21st, 2013, 01:28 AM
It sounds like you are asking for logic that alters the content of your front end rather than a FusionPro-generated document. In that case, you might want to post this in the Marcom Central section for specific information. I am not an MC user so I can't help in that regard.

brians
February 21st, 2013, 01:30 AM
Thanks Eric. I kind of thought that might be the case. Thanks again for getting me this far.