BPM Code Help with DateTime Check OrderRel ReqDate at Shipment

Hello,

I am looking to complete a BPM that will show an InfoMessage when a user pulls Sales Order Line/Rel into a PackNum in Customer Shipment Entry. The InfoMessage should show when the corresponding Order/Line/Rel ReqDate is in the past (less than today’s date). The InfoMessage is strictly informational and will not stop processing.

I have pieced together a Post BPM on Erp.CustShip.GetOrderRelInfo.
This mostly works, outside of one condition.
In my testing I have three line/releases on an order with ReqDate:

  1. Earlier than Today - Works
  2. Later than Today - Works
  3. Equal to Today - Does Not Work

The only way I could figure out what I’m looking for was to key in on OrderRel_Row.ReqDate < DateTime.Now
I know the DateTIme.Now format will take into consideration the time of day not just the date itself. This is why my message fires for a release with a ReqDate of today (which I’m trying to make not happen).

So my question is two fold.

  1. Is this BPM a viable way to handle this?
  2. What can I change in the Custom Code to handle when the date is today?

Any help is much appreciated.
Thanks,
Joe

DateTime vShipTimeNow;
string vRelReqDate;
int vOrderNum = 0;
int vOrderLine = 0;
int vOrderRelNum = 0;
string newDate1;


Erp.Tables.OrderRel OrderRel;
 
var tempShipDtlRow = (from ttrow in ttShipDtl
                     where ttrow.Company == Session.CompanyID        
                    select ttrow).FirstOrDefault();
                    
  if (tempShipDtlRow != null)
    
    {
      vOrderNum = tempShipDtlRow.OrderNum;
      vOrderLine = tempShipDtlRow.OrderLine;
      vOrderRelNum = tempShipDtlRow.OrderRelNum;
      vShipTimeNow = DateTime.Now.Date;
      newDate1 = String.Format("{0:d}", vShipTimeNow).ToString();
      //this.PublishInfoMessage("Today: " + newDate1, Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Individual, "Application Name", "Comments");
    }
  
  
      foreach (var OrderRel_Recs in (from OrderRel_Row in Db.OrderRel 
       where OrderRel_Row.Company == Session.CompanyID 
       && OrderRel_Row.OrderNum == vOrderNum
       && OrderRel_Row.OrderLine == vOrderLine
       && OrderRel_Row.OrderRelNum == vOrderRelNum
       && OrderRel_Row.ReqDate < DateTime.Now
       select OrderRel_Row)) 
        
      {
        var OrderRel_Row = OrderRel_Recs;
       
         {
          
          vRelReqDate = OrderRel_Row.ReqDate.ToString();
          string newDate2 = String.Format("{0:d}", OrderRel_Row.ReqDate);
          this.PublishInfoMessage("Order/Line/Release: " + vOrderNum.ToString() + " / " + vOrderLine.ToString() + " / " + vOrderRelNum.ToString() + "\r" + "Is Shipping Late"+ "\r"  + "Order Release ShipDate: " + newDate2, Ice.Common.BusinessObjectMessageType.Warning, Ice.Bpm.InfoMessageDisplayMode.Individual, "", "");
  
         }
      }

I believe the time portion of a DateTime, is represented as the fraction of the day.

12345.25 is 6 hours (0.25 of a day) past midnight of day 12345.

So just compare the whole number parts of the DateTimes.

Thanks Calvin…

Any leads on what syntax would work to convert DateTime.Now to a integer?

I used Convert.ToInt32(DateTime.Now) and tired to just place the variable in a message box so I could see it when the BPM fires, Even though the syntax checks out fine in the BPM editor, I get a runtime error form the form when it fires the BPM.

Invalid cast from ‘DateTime’ to ‘Int32’.

This query did this trick… Thanks for the hints Calvin.

vShipTimeToday =  DateTime.Today;
foreach (var OrderRel_Recs in (from OrderRel_Row in Db.OrderRel 
 where OrderRel_Row.Company == Session.CompanyID 
 && OrderRel_Row.OrderNum == vOrderNum
 && OrderRel_Row.OrderLine == vOrderLine
 && OrderRel_Row.OrderRelNum == vOrderRelNum
 && OrderRel_Row.ReqDate < vShipTimeToday
 select OrderRel_Row))