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.
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:
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.
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.
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.
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.
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.