# BPM help

**URL:** <https://www.epiusers.help/t/bpm-help/52863>\
**Category:** Epicor ERP 10\
**Tags:** bpm\
**Created:** [February 21, 2019, 3:20pm UTC](https://www.epiusers.help/t/bpm-help/52863 "2019-02-21T15:20:57Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![BoostERP](https://www.epiusers.help/user_avatar/www.epiusers.help/boosterp/32/13342_2.png) [@BoostERP](https://www.epiusers.help/u/BoostERP)\
**Post date:** [February 21, 2019, 3:20pm UTC](https://www.epiusers.help/t/bpm-help/52863/1 "2019-02-21T15:20:57Z")

</div>

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

 ![image](https://epiusers.help/uploads/default/original/2X/f/f7be9bb680cac31c07dcb55cab08ad4c4f2cb4b2.jpeg)

 ![image](https://epiusers.help/uploads/default/original/2X/3/39afaa4209a4e660775b4777b2b9f23079cc0109.jpeg)

---

<div class="post-metadata">

**Author:** ![tsmith](https://www.epiusers.help/user_avatar/www.epiusers.help/tsmith/32/64774_2.png) [@tsmith](https://www.epiusers.help/u/tsmith)\
**Post date:** [February 21, 2019, 3:25pm UTC](https://www.epiusers.help/t/bpm-help/52863/2 "2019-02-21T15:25:32Z")

</div>

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

```cs
(ttOrderHedRow.RequestDate - ttOrderHedRow.OrderDate).Days

```

---

<div class="post-metadata">

**Author:** ![Banderson](https://www.epiusers.help/user_avatar/www.epiusers.help/banderson/32/50875_2.png) [@Banderson](https://www.epiusers.help/u/Banderson)\
**Post date:** [February 21, 2019, 3:26pm UTC](https://www.epiusers.help/t/bpm-help/52863/3 "2019-02-21T15:26:40Z")

</div>

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

> <https://stackoverflow.com/questions/1607336/calculate-difference-between-two-dates-number-of-days>

---

<div class="post-metadata">

**Author:** ![BoostERP](https://www.epiusers.help/user_avatar/www.epiusers.help/boosterp/32/13342_2.png) [@BoostERP](https://www.epiusers.help/u/BoostERP)\
**Post date:** [February 21, 2019, 3:30pm UTC](https://www.epiusers.help/t/bpm-help/52863/4 "2019-02-21T15:30:11Z")

</div>

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

 ![image](https://epiusers.help/uploads/default/original/2X/7/772fdf8b74c0065d99f185df452a4d767bbd3e46.png)

---

<div class="post-metadata">

**Author:** ![BoostERP](https://www.epiusers.help/user_avatar/www.epiusers.help/boosterp/32/13342_2.png) [@BoostERP](https://www.epiusers.help/u/BoostERP)\
**Post date:** [February 21, 2019, 3:40pm UTC](https://www.epiusers.help/t/bpm-help/52863/5 "2019-02-21T15:40:06Z")

</div>

My variable looks like this if it helps…

 ![image](https://epiusers.help/uploads/default/original/2X/c/c972d23304d35df678fedbf5c8aa0268ca15501a.png)

---

<div class="post-metadata">

**Author:** ![tsmith](https://www.epiusers.help/user_avatar/www.epiusers.help/tsmith/32/64774_2.png) [@tsmith](https://www.epiusers.help/u/tsmith)\
**Post date:** [February 21, 2019, 3:42pm UTC](https://www.epiusers.help/t/bpm-help/52863/6 "2019-02-21T15:42:22Z")

</div>

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:

```cs
(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.

---

<div class="post-metadata">

**Author:** ![BoostERP](https://www.epiusers.help/user_avatar/www.epiusers.help/boosterp/32/13342_2.png) [@BoostERP](https://www.epiusers.help/u/BoostERP)\
**Post date:** [February 21, 2019, 3:47pm UTC](https://www.epiusers.help/t/bpm-help/52863/7 "2019-02-21T15:47:14Z")

</div>

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

 ![image](https://epiusers.help/uploads/default/original/2X/4/4fd88b74d5a2a89aa237f5eed97ab7dcc61ddd52.png)

---

<div class="post-metadata">

**Author:** ![BoostERP](https://www.epiusers.help/user_avatar/www.epiusers.help/boosterp/32/13342_2.png) [@BoostERP](https://www.epiusers.help/u/BoostERP)\
**Post date:** [February 21, 2019, 3:57pm UTC](https://www.epiusers.help/t/bpm-help/52863/8 "2019-02-21T15:57:49Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Banderson](https://www.epiusers.help/user_avatar/www.epiusers.help/banderson/32/50875_2.png) [@Banderson](https://www.epiusers.help/u/Banderson)\
**Post date:** [February 21, 2019, 4:00pm UTC](https://www.epiusers.help/t/bpm-help/52863/9 "2019-02-21T16:00:24Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Banderson](https://www.epiusers.help/user_avatar/www.epiusers.help/banderson/32/50875_2.png) [@Banderson](https://www.epiusers.help/u/Banderson)\
**Post date:** [February 21, 2019, 4:01pm UTC](https://www.epiusers.help/t/bpm-help/52863/10 "2019-02-21T16:01:24Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![BoostERP](https://www.epiusers.help/user_avatar/www.epiusers.help/boosterp/32/13342_2.png) [@BoostERP](https://www.epiusers.help/u/BoostERP)\
**Post date:** [February 21, 2019, 4:04pm UTC](https://www.epiusers.help/t/bpm-help/52863/11 "2019-02-21T16:04:43Z")

</div>

Excellent idea. Thanks for the help!

---

<div class="post-metadata">

**Author:** ![BoostERP](https://www.epiusers.help/user_avatar/www.epiusers.help/boosterp/32/13342_2.png) [@BoostERP](https://www.epiusers.help/u/BoostERP)\
**Post date:** [February 21, 2019, 6:21pm UTC](https://www.epiusers.help/t/bpm-help/52863/12 "2019-02-21T18:21:53Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Banderson](https://www.epiusers.help/user_avatar/www.epiusers.help/banderson/32/50875_2.png) [@Banderson](https://www.epiusers.help/u/Banderson)\
**Post date:** [February 21, 2019, 6:24pm UTC](https://www.epiusers.help/t/bpm-help/52863/13 "2019-02-21T18:24:18Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![BoostERP](https://www.epiusers.help/user_avatar/www.epiusers.help/boosterp/32/13342_2.png) [@BoostERP](https://www.epiusers.help/u/BoostERP)\
**Post date:** [February 21, 2019, 6:45pm UTC](https://www.epiusers.help/t/bpm-help/52863/14 "2019-02-21T18:45:32Z")

</div>

Here are my current conditions.

 ![image](https://epiusers.help/uploads/default/original/2X/4/41a0d6991138487c984503cc1f425bce66d4f134.png)

---

<div class="post-metadata">

**Author:** ![Banderson](https://www.epiusers.help/user_avatar/www.epiusers.help/banderson/32/50875_2.png) [@Banderson](https://www.epiusers.help/u/Banderson)\
**Post date:** [February 21, 2019, 7:07pm UTC](https://www.epiusers.help/t/bpm-help/52863/15 "2019-02-21T19:07:29Z")

</div>

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)

 ![image](https://epiusers.help/uploads/default/original/2X/e/e94307da39ce89721279140d933e6f43f1e8b8ae.png)

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.

 ![image](https://epiusers.help/uploads/default/original/2X/2/2eda09d52f6dcfd8f30296008b0a9b2c57743837.png)

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](https://epiusers.help/uploads/default/original/2X/f/f225369d56d22d801ce96b81aedf697325a54e58.png)

![image](https://epiusers.help/uploads/default/original/2X/4/47a777fb1e4c9046a29399ebc9d308d03a372fca.png)

---

<div class="post-metadata">

**Author:** ![BoostERP](https://www.epiusers.help/user_avatar/www.epiusers.help/boosterp/32/13342_2.png) [@BoostERP](https://www.epiusers.help/u/BoostERP)\
**Post date:** [February 21, 2019, 7:18pm UTC](https://www.epiusers.help/t/bpm-help/52863/16 "2019-02-21T19:18:40Z")

</div>

Thanks for the help.

---

<div class="post-metadata">

**Author:** ![Banderson](https://www.epiusers.help/user_avatar/www.epiusers.help/banderson/32/50875_2.png) [@Banderson](https://www.epiusers.help/u/Banderson)\
**Post date:** [February 21, 2019, 7:19pm UTC](https://www.epiusers.help/t/bpm-help/52863/17 "2019-02-21T19:19:13Z")

</div>

Let me know if it works.

---

<div class="post-metadata">

**Author:** ![BoostERP](https://www.epiusers.help/user_avatar/www.epiusers.help/boosterp/32/13342_2.png) [@BoostERP](https://www.epiusers.help/u/BoostERP)\
**Post date:** [February 21, 2019, 8:26pm UTC](https://www.epiusers.help/t/bpm-help/52863/18 "2019-02-21T20:26:52Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Banderson](https://www.epiusers.help/user_avatar/www.epiusers.help/banderson/32/50875_2.png) [@Banderson](https://www.epiusers.help/u/Banderson)\
**Post date:** [February 21, 2019, 10:07pm UTC](https://www.epiusers.help/t/bpm-help/52863/19 "2019-02-21T22:07:12Z")

</div>

> [@Banderson](#):
>
> 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.
> 
> ![image.png](https://epiusers.help/uploads/default/original/2X/2/2eda09d52f6dcfd8f30296008b0a9b2c57743837.png)

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.

 ![image](https://www.epiusers.help/uploads/default/original/2X/a/a91fb34ffcc7b1e1c1b028e25ea91238ff53a76a.png)

Then in the post your condition will be this.

 ![image](https://www.epiusers.help/uploads/default/original/2X/6/6d8e408b7cfc4c5ed86b424e55567ce2d383c8ba.png)

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