BPM to validate the request date on the orderhed is not on a weekend


Working on a BPM to validate the Request Date on the Order is not on a weekend. Could you please provide a recommendation on how to achieve this?


Hello @jkim

Give this a try - it gives you the option to throw an error message or to auto change the entered date to Monday


var order = ttOrderHed.Where(o => o.Company == Session.CompanyID && o.RequestDate != null && (o.RowMod == "A" || o.RowMod == "U")).FirstOrDefault();
if(order != null)
var rDate = order.RequestDate;
if(rDate.Value.DayOfWeek == DayOfWeek.Sunday)
//Uncomment the following line if you want to throw an error message
// throw new Ice.BLException("The Ship By day falls on Sunday, please change");

//Uncomment the following line to auto change the date to Monday
// order.RequestDate = rDate.Value.AddDays(1);  
if(rDate.Value.DayOfWeek == DayOfWeek.Saturday)
//Uncomment the following line if you want to throw an error message
// throw new Ice.BLException("The Ship By day falls on Saturday, please change");  

//Uncomment the following line to auto change the date to Monday
// order.RequestDate = rDate.Value.AddDays(2);

You can also add negative numbers to move the date back to Friday

order.RequestDate = rDate.Value.AddDays(-1);

you can also stamp the order date to a parameter ( on @LBARKER BPM) then run a SQL expression statement in a criteria (Saturday or Sunday) or any day you want, if yes then raise an exception with informative message.



But ideally, using you Calendar should be your solution ! What if the date is in a holiday ? What then?
Your calendar should have all those exceptions…if well configured…

I am still sckeptical as why Epicor has not yet implemented such feature !! :thinking:
The use of our calendar to find either previous or next working days.


1 Like

totally agree, i had constructed a calendar driven solution to try that on certain BO but found it too messy, so i have stopped.

Thank you. It is working perfectly. Appreciate your help.

I used a UD table to input our Holiday days in. Those records auto update all our resource calendars with exceptions. I also use it to validate request days.

I took the same code and opportunity to do range exceptions (example a machine is busted waiting for parts but we don’t want to throw the whole calendar into disarray or go check day by day by day)

foreach(var tt in ttUD03.Where(x => x.Key1 == "ProdCalHoliday"))
  var allRes = Db.ResourceGroup.Where(x => x.Inactive == false).ToList();
  foreach(var rg in allRes)
    using (var rgSvc = Ice.Assemblies.ServiceRenderer.GetService<Erp.Contracts.ResourceGroupSvcContract>(Db))
        ResourceGroupTableset rgDs = new ResourceGroupTableset();
        rgDs = rgSvc.GetByID(rg.ResourceGrpID);      
        rgSvc.CustomizeResourceCalRsrcGrp(rg.ResourceGrpID, tt.Date01, ref rgDs);
        var modified = rgDs.ResourceCal.Where(x => x.ResourceGrpID == rg.ResourceGrpID && x.SpecialDay == tt.Date01).FirstOrDefault();
        if(modified != null)
          modified.ExceptionLabel = tt.Character01;
          modified.ProdHour01 = false;
          modified.ProdHour02 = false;
          modified.ProdHour03 = false;
          modified.ProdHour04 = false;
          modified.ProdHour05 = false;
          modified.ProdHour06 = false;
          modified.ProdHour07 = false;
          modified.ProdHour08 = false;
          modified.ProdHour09 = false;
          modified.ProdHour10 = false;
          modified.ProdHour11 = false;
          modified.ProdHour12 = false;
          modified.ProdHour13 = false;
          modified.ProdHour14 = false;
          modified.ProdHour15 = false;
          modified.ProdHour16 = false;
          modified.ProdHour17 = false;
          modified.ProdHour18 = false;
          modified.ProdHour19 = false;
          modified.ProdHour20 = false;
          modified.ProdHour21 = false;
          modified.ProdHour22 = false;
          modified.ProdHour23 = false;       
          modified.ProdHour24 = false;
          modified.RowMod = "U";
        rgSvc.UpdateResourceCal(ref rgDs);        
        rgDs = null;
      catch (Exception ex)
  this.PublishInfoMessage($"This holiday exception for {((DateTime)tt.Date01).Date} has been added to the Production Calendars", 0, 0, String.Empty, String.Empty);

I also customized the production calendars to include a total hours per day. I use that then to filter request dates based on if X day has 0 hours on our company calendar. Counting checkboxes is for the birds I wish Epicor had these summary columns by default, but not the ditch worth dying in today :smiley:

1 Like

Even better would be if they just used StartTime and Production Hours instead of the checkboxes. I’m sure they get some processing performance advantage by hour blocks, but it seems both complicated to setup/maintain and inflexible.
I’ve taken to adding a custom field for shift pattern to the calendar and have a UD table that holds the different shift patterns (Single Shift, Single Extended, Double Shift, Triple Shift, etc) hours. When you change the calendar shift pattern, it copies the hours from the UD table to the calendar. Also works for exceptions. Makes reporting what we’re running per line easier.