Jump to content

Setting a turnaround level based on mail drop date?


Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...