BPM help

So I am trying to create a BPM that subtracts the order header request date (ship by) from the order date and then send out an email if that time frame is shorter than x amount of days.

I am getting an error(s) when I try to subtract the two dates. I can do this on the BAQ side no problem and get what I need. The C# expression is kicking by butt. I really haven’t and don’t do much with C#.

I am have a OrderLeadTime variable as an integer and then trying to subtract the two dates to get a number of days in between them.

Appreciate any help on this. Thanks.

Brad

You can use this: (Updated to use .Days method which returns an Int32)

(ttOrderHedRow.RequestDate - ttOrderHedRow.OrderDate).Days
3 Likes

Here’s a link as well. (@tsmith you beat me to the answer!)

2 Likes

OK, I did try that and that gives me this error…

My variable looks like this if it helps…

Since the TimeSpan created from the date subtraction is nullable, you need to add a .Value before the .Days to get the underlying value. You can (and probably should) add a null check to make sure it isn’t null first:

(ttOrderHedRow.RequestDate - ttOrderHedRow.OrderDate).HasValue ? (ttOrderHedRow.RequestDate - ttOrderHedRow.OrderDate).Value.Days : 0

This will default the number of days to 0 if the subtraction results in a null value (which I think would happen if either date is blank). Otherwise, it will give you the number of days between the two dates.

If you want to skip sending an email when there isn’t a Request Date entered yet, you can change the 0 to a value greater than your email threshold.

4 Likes

YEAAAAH! I would have never got that without your help.

2 Likes

OK so this working, but it sends an email out EVERY time the save (update) is done. it there a better way to do this without peppering people with ten emails for the same order?

Should I have used a Get New method instead of an Update method?

You won’t have any dates GetNew, so that wouldn’t work.

That’s the hard part about sending e-mails, is trying to figure out when to send and when not too. I try to use exception dashboards instead, (and BAQ gadgets) because it just looks that the current state rather than trying to find an event to trigger off of.

You can probably do a condition that looks for only when the date field(s) is changing. That way if something else changes, it doesn’t need to send a duplicate e-mail.

1 Like

Excellent idea. Thanks for the help!

That condition idea worked perfectly. Only if the order header request field is updated do I get an email.

My last hurdle is a new order being entered. I am not getting am email in this scenario. Any thoughts?

Thanks again.
Brad

What does your condition look like? Do you just need to add OR if there is an added row?

Here are my current conditions.

So basically we just need to check for when there is a new row. The Data directives do a little better job with things like looking for an added row. So ultimately, I think it would be better if you move your stuff to there, (here’s a screen shot of the conditions I would use)

But if you want to continue on with your method directive, give this a shot and see what it does. Add this to your current conditions. Basically, we just want to trigger if (there is a change to the date, OR if there is a new row) AND your date condition is too narrow.

Don’t forget the parenthesis.

Pro tip, put message boxes in with table queries to show your data. It makes troubleshooting this stuff WAY easier. For data directive, you’ll have to get everything set in in an in transaction directive, except for the e-mail, because that doesn’t work in in-trans, but then you can move over all of the logic to a standard. (because message boxes don’t work in standard). Although I supposed you could use E-mails for the same thing.

image

image

Thanks for the help.

Let me know if it works.

The data directive worked. Thanks again for all the help!

1 Like

Hey I just wanted to add some info on this since I am working on my own BPM right now. This doesn’t work! The post processing doesn’t have Row mods, so this doesn’t work. What you have to do it make a pre-processing that checks for an added row and set s and enable post directive like this.

Then in the post your condition will be this.

Just wanted to correct his in case anyone came along later and tried something that wasn’t going to work.