BPM to send email to dispatcher in Purchase Req

I am trying to find a way to send an email to the next dispatcher of a Purchase Req. Since the ReqHead table does not have an email address field, I would assume that you would need to do a search within the UserFile table and compare it the the ReqHead.NextDispatcherID. Unfortunately, I do not know how to exactly do this. Does anyone do this? How exactly do you do it?

Thanks,
Adam Smith

Here’s part of an email notice that we had in V8. It retrieved an email address from UD table UD05. You should substitute:

  • UserFile for UD05
  • DcdUserID for ShortChar01
  • ReqHead.NextDispatcherID for pm (in the Where clause)
  • your variable that holds the email address for pmEmail
  • EMailAddress for ShortChar02
DEFINE VARIABLE pmEmail AS CHARACTER NO-UNDO.

FIND FIRST UD05 WHERE (Ud05.Company = 'MC') AND (UD05.ShortChar01 = pm) NO-LOCK NO-ERROR.
IF AVAILABLE UD05 THEN DO:
  pmEmail = UD05.ShortChar02.
END.

If you need other values from the User File, retriev them in that IF AVAILABLE ... END block

Did you just need help with getting the email from the userfile? Or do you need help for the whole thing?

Actually the whole thing. I currently created a PreProcess on the Req.Update method.
My condition is setup as:
the ttReqHead.NextDispatcherID field has been changed from any to “michael.billings”

The Action is setup as - synchronously execute 4GL code:
FIND UserFile WHERE (UserFile.DcdUserID = ttReqHead.NextDispatcherID) NO-LOCK NO-ERROR.
ttReqHead.ShortChar01 = UserFile.EMailAddress.

The condition does trigger the process, but I get an error saying: "ERROR condition: The Server application has returned an error. (7243) (7211) "

In my testing, it looks like the error is triggered whenever I try to assign a field to something.

Been a few years since I did this in V8. I don’t recall the exact terminology in V8 so I’ll describe them as I remember:

  1. We used the system that can log / send an email / or run a program upon change of a DB field. (What are called Data Directives in E10)
  2. This monitored the ShipHead table for a change of the shipping status flag, to “SHIPPED”
  3. We had it execute a program that I wrote.
    a. a text file named “ShipmentAlert.p”
    b. that file resided in “E:Epicor\mfgsys803\Server\ud\Alerts” on the server
  4. The ShipmentAlert.p program would receive use ShipHead as the inputs, build the email, and then send it.

Before any of that would work, is your V8 currently capable of sending emails?

I can sen you the ShipmentAlert.p file for you to look at. It’s moderately documented. But if you’ve not programmed in 4GL/ABL (not sure exactly what Progress calls it), it might not make sense.

.

Calvin.

Yes, my system is capable of sending emails. I can hard code my email address in and I get the email. However, I do not want the emails to come to only me. I want the email to go to the person that needs to dispatch the requisition, which that person could be anybody, hence the need to lookup their email address from the UserFile table. If you could send me that program, I can see what I can do to decipher it.

Much appreciated.

One thing I recall. We used a BAM (Business Activity Monitor) - what E10 now calls a Data Directive.

I’ll try to pull together the info this weekend.

Hi Calvin,
I know this is an old discussion. Did you manage to create the data directive for sending emails to the dispatcher in Purchase Req?
I seem to get a single req line in the email notification sent using the Req update method, although I have a multiple line requisition.

I never did follow-up on that (sorry to the original poster).

Here’s the .p code that would be executed. This particular code builds an email body for use in a BAM

V8 - ShipmentAlert-2016-09-14a.p
/* Finshed: 2/12/16 */

/* 2/13/2016 CRK
 - Added displaying open items 
 
    2/16/16 CRK
 - Added code to fix (tm) char
 
    2/18/16 CRK
 - added To and CC emails to body text
 
    2/21/16  CRK
 - added function for converting odd characters

    2/23/16  CRK
 - Fixed part desc

    2/24/16  CRK
 - added Silvia (<slaemmle@example.com>) to CC list

    3/19/16  CRK
 - added Lisa (<slporter@example.com>) to CC list
 
    6/1/16 CRK
- Added checks for FIND FIRST calls to see if record is available, before using it.
- Using input param 'Email-CC' as initial list of for people to be CC'd.  
  In the future, just update the CC: list in the BAM, instead of this code.

	9/14/16 CRK
- Fixed "Ship TO name".  Was displaying Customer.Name
***************************/

FUNCTION foo RETURNS CHARACTER (s AS CHARACTER):
  s = REPLACE(s, ">", "&gt;").
  s = REPLACE(s, "<", "&lt;").
  s = REPLACE(s, CHR(49833), "&copy;").
  s = REPLACE(s, CHR(49838), "&reg;").
  s = REPLACE(s, CHR(14844060),CHR(34)).
  s = REPLACE(s, CHR(14844061),CHR(34)).
  s = REPLACE(s, CHR(14845090), "&trade;").
  s = REPLACE(s, CHR(14844588), "&euro;").
  RETURN s.
END.


{ud/GlbAlert.i &TableName = "ShipHead"}
DEFINE VARIABLE NewEmailBody AS CHARACTER NO-UNDO.
DEFINE VARIABLE tn AS CHARACTER NO-UNDO.
DEFINE VARIABLE ordNum as INTEGER NO-UNDO.
DEFINE VARIABLE ordCount as INTEGER NO-UNDO.
DEFINE VARIABLE lastOrdNum as INTEGER NO-UNDO.
DEFINE VARIABLE jeNum AS CHARACTER NO-UNDO.
DEFINE VARIABLE pm AS CHARACTER NO-UNDO.
DEFINE VARIABLE pmEmail AS CHARACTER NO-UNDO.
DEFINE VARIABLE thisPackNum as INTEGER NO-UNDO.
DEFINE VARIABLE lastPackNum as INTEGER NO-UNDO.
DEFINE VARIABLE opLineRel AS CHARACTER NO-UNDO.
DEFINE VARIABLE ts AS CHARACTER NO-UNDO.
DEFINE VARIABLE td AS DATE INITIAL TODAY NO-UNDO.
DEFINE VARIABLE cc AS CHARACTER NO-UNDO.

tn = STRING(ShipHead.TrackingNumber).
thisPackNum = ShipHead.PackNum.
pmEmail = "ckrusen@example.com".

ASSIGN Email-Mime-Header = "type=text/html:charset=us-ascii:filetype=ascii".

/************************************/
/* Create the new body of the email */
ASSIGN NewEmailBody = "<html><body><pre style='font: monospace'>".

NewEmailBody = NewEmailBody + "(This is an automated message. Please do not reply)" + chr(10) + chr(10).
NewEmailBody = NewEmailBody + "<b>FOR INTERNAL USE ONLY !!!</b>" + chr(10).

ordCount = 0.
lastOrdNum = -1.


/********************************************************************/
/* Get related Order info - J&E Num, Vista Num, PM, PM's email, ... */
FIND FIRST ShipDtl WHERE (ShipDtl.Company = ShipHead.Company) AND (ShipDtl.PackNum = ShipHead.PackNum) NO-LOCK NO-ERROR.
ordNum = ShipDtl.OrderNum.

FIND FIRST OrderHed WHERE (OrderHed.Company = 'MC') AND (OrderHed.OrderNum = ordNum) NO-LOCK NO-ERROR.
IF AVAILABLE OrderHed  Then DO:
  pm = OrderHed.ShortChar09.
  jeNum = OrderHed.ShortChar02.
END.

FIND FIRST UD05 WHERE (Ud05.Company = 'MC') AND (UD05.ShortChar01 = pm) NO-LOCK NO-ERROR.
IF AVAILABLE UD05 THEN pmEmail = UD05.ShortChar02.


ASSIGN Email-Subject = "Shipment Notification.  Order#: " + jeNum + " / " + STRING(OrderHed.OrderNum) + ", Packer#: " + STRING(ShipHead.PackNum).

/*****************************/
/* build order shipment info */

/* todays packers */
FIND Customer WHERE (Customer.Company = ShipHead.Company) AND (Customer.CustNum = ShipHead.CustNum) NO-LOCK.
FIND ShipDtl WHERE (ShipDtl.Company = ShipHead.Company) AND (ShipDtl.PackNum = ShipHead.PackNum) NO-LOCK NO-ERROR.
FIND ShipTo WHERE (ShipTo.Company = ShipHead.Company) AND (ShipTo.CustNum = ShipHead.CustNum) AND (ShipTo.ShipToNum = ShipHead.ShipToNum) NO-LOCK NO-ERROR.

NewEmailBody = NewEmailBody +       "************************ THIS SHIPMENT ************************ " + chr(10).
NewEmailBody = NewEmailBody + "Packer: " + STRING(ShipHead.PackNum) + ",  J&E Job#:" + jeNum + ",  Vista Order#:" + STRING(ordNum) + chr(10).
NewEmailBody = NewEmailBody + "Tracking #(s): " + foo(tn) + chr(10) + chr(10).
NewEmailBody = NewEmailBody + "Ship To:" + chr(10).
NewEmailBody = NewEmailBody + foo(ShipTo.Name) + " (" + STRING(Customer.CustId) + ")" + chr(10).
NewEmailBody = NewEmailBody + foo(ShipTo.Address1) + chr(10).
if length(ShipTo.Address2) > 1 then NewEmailBody = NewEmailBody + foo(ShipTo.Address2) + chr(10).
if length(ShipTo.Address3) > 1 then NewEmailBody = NewEmailBody + foo(ShipTo.Address3) + chr(10).
NewEmailBody = NewEmailBody + foo(ShipTo.City) + ", " + foo(ShipTo.State) + "  " +  foo(ShipTo.ZIP) + chr(10).
NewEmailBody = NewEmailBody + chr(10).

NewEmailBody = NewEmailBody + "Ord  Shp     Shp  Part                       Part" + chr(10).
NewEmailBody = NewEmailBody + "Line Qty     UOM  Number                     Description" + chr(10).
NewEmailBody = NewEmailBody + "==== ======= ===  =========================  =========================" + chr(10).

FOR EACH ShipDtl WHERE (ShipDtl.Company = ShipHead.Company) AND (ShipDtl.PackNum = ShipHead.PackNum):
  if( INDEX(ShipDtl.PartNum,"FREIGHT") = 0) then do:
    NewEmailBody = NewEmailBody + STRING(ShipDtl.OrderLine)  + FILL(" ",5 - LENGTH(STRING(ShipDtl.OrderLine))).
    NewEmailBody = NewEmailBody + STRING((ShipDtl.SellingInventoryShipQty + ShipDtl.SellingJobShipQty)).
    NewEmailBody = NewEmailBody + FILL(" ", 8 - LENGTH(STRING(ShipDtl.SellingInventoryShipQty + ShipDtl.SellingJobShipQty))).
    NewEmailBody = NewEmailBody + foo(ShipDtl.SalesUM + FILL(" ",5 - LENGTH(ShipDtl.SalesUM))).
    NewEmailBody = NewEmailBody + foo(SUBSTR(ShipDtl.PartNum,1,25) + FILL(" ",27 - LENGTH(ShipDtl.PartNum))).
    ts = substr(ShipDtl.LineDesc,1,25).
    IF(LENGTH(ts) >= 25) THEN ts = SUBSTR(ts,1,22) + "...".
    ts = foo(ts).
    NewEmailBody = NewEmailBody + ts.
    NewEmailBody = NewEmailBody + chr(10).
  END.
END.

/* end of finding orders for this shipment*/
NewEmailBody = NewEmailBody + chr(10) + chr(10).

/* find previous shipments for this order */
FOR First ShipDtl WHERE (ShipDtl.Company = ShipHead.Company  AND ShipDtl.OrderNum = ordNum AND ShipDtl.PackNum <> thisPackNum):
  NewEmailBody = NewEmailBody +       "************************ PREVIOUS SHIPMENTS ************************ " + chr(10).
end.

lastPackNum = 0.
FOR EACH ShipDtl WHERE (ShipDtl.Company = ShipHead.Company  AND ShipDtl.OrderNum = ordNum)  BY ShipDtl.PackNum DESCENDING:
  if(ShipDtl.PackNum <> thisPackNum) then do:
    if(ShipDtl.PackNum <> lastPackNum) then do:
      NewEmailBody = NewEmailBody + chr(10) + "Packer#: " + STRING(ShipDtl.PackNum) + chr(10).  
      NewEmailBody = NewEmailBody + "Ord  Shp     Shp  Part                       Part" + chr(10).
      NewEmailBody = NewEmailBody + "Line Qty     UOM  Number                     Description" + chr(10).
      NewEmailBody = NewEmailBody + "==== ======= ===  =========================  =========================" + chr(10).
      lastPacknum = ShipDtl.PackNum.
    end.
    NewEmailBody = NewEmailBody + STRING(ShipDtl.OrderLine)  + FILL(" ",5 - LENGTH(STRING(ShipDtl.OrderLine))).
    NewEmailBody = NewEmailBody + STRING((ShipDtl.SellingInventoryShipQty + ShipDtl.SellingJobShipQty)).
    NewEmailBody = NewEmailBody + FILL(" ", 8 - LENGTH(STRING(ShipDtl.SellingInventoryShipQty + ShipDtl.SellingJobShipQty))).
    NewEmailBody = NewEmailBody + foo(ShipDtl.SalesUM + FILL(" ",5 - LENGTH(ShipDtl.SalesUM))).
    NewEmailBody = NewEmailBody + foo(SUBSTR(ShipDtl.PartNum,1,25) + FILL(" ",27 - LENGTH(ShipDtl.PartNum))).

    ts = substr(ShipDtl.LineDesc,1,25).
    IF(LENGTH(ts) >= 25) THEN ts = SUBSTR(ts,1,22) + "...".
    ts = foo(ts).
    NewEmailBody = NewEmailBody + ts.
    NewEmailBody = NewEmailBody + chr(10).
  end.
end.




ASSIGN Email-Subject = "Shipment Notification.  Order#: " + jeNum + " / " + STRING(OrderHed.OrderNum) + ", Packer#: " + STRING(ShipHead.PackNum).

/***************************
  FOR FIRST OrderRel WHERE (OrderRel.Company = 'MC' AND OrderRel.OrderNum = ordNum AND OrderRel.OpenRelease):
    NewEmailBody = NewEmailBody + chr(10) + chr(10) + "************************ OPEN LINES ************************ " + chr(10).  
    NewEmailBody = NewEmailBody + "Line  Rel    Part                       Open   Req       " + chr(10).
    NewEmailBody = NewEmailBody + "-Rel  Qty    Number                     Qty    Date      " + chr(10).
    NewEmailBody = NewEmailBody + "===== ====== =========================  ====== ==========" + chr(10).

  end.
  FOR EACH OrderRel WHERE (OrderRel.Company = 'MC' AND OrderRel.OrderNum = ordNum AND OrderRel.OpenRelease):
    opLineRel = STRING(OrderRel.OrderLine) + "-" + STRING(OrderRel.OrderRelNum).
    NewEmailBody = NewEmailBody + opLineRel + FILL(" ",6 - LENGTH(opLineRel)).
    NewEmailBody = NewEmailBody + STRING(OrderRel.OurReqQty) + FILL(" ",7 - LENGTH(STRING(OrderRel.OurReqQty))).
    NewEmailBody = NewEmailBody + SUBSTR(OrderRel.PartNum,1,25) + FILL(" ",27 - LENGTH(OrderRel.PartNum)).
    ts = STRING(OrderRel.OurReqQty - (OrderRel.OurJobShippedQty + OrderRel.OurStockShippedQty)).
    NewEmailBody = NewEmailBody +  foo(ts + FILL(" ",7 - LENGTH(ts))).
    ts = "".
    if (OrderRel.ReqDate > DATE(1,1,2000)) THEN ts = STRING(OrderRel.ReqDate,"99/99/9999").
    NewEmailBody = NewEmailBody + ts.
    NewEmailBody = NewEmailBody + chr(10).
  end.
***********************************/

/* debugging stuff */
IF (pmEmail = "me@example.com") then do:
  /********
  NewEmailBody = NewEmailBody + chr(10) + STRING(ASC(SUBSTR(tn,1,1))).
  NewEmailBody = NewEmailBody + chr(10) + STRING(ASC(SUBSTR(tn,2,1))).
  NewEmailBody = NewEmailBody + chr(10) + STRING(ASC(SUBSTR(tn,3,1))).
  NewEmailBody = NewEmailBody + chr(10) + STRING(ASC(SUBSTR(tn,4,1))).
  ************/
END.


ASSIGN Email-To = "<" + REPLACE(pmEmail,";",">;<") + ">".

/*cc = "<rjacobs@example.com>; <jpacheco@example.com>; <ejacob@example.com>; <slaemmle@example.com>; <lporter@example.com>; <calvin.krusen@verizon.net>;".*/
/* get CC list from BAM */
cc = Email-CC.

/* remove PM from CC: */
cc = REPLACE(cc, Email-To, "; ").

/* overide the CC list when I'm the PM - This is for testing so others don't get the test messages */
IF (pmEmail = "ckrusen@example.com") then cc = "<calvin.krusen@personal-email.net>".
ASSIGN Email-CC = cc.

/* add To and CC to body text.  This is just fro debugging*/
/***********
NewEmailBody = NewEmailBody + chr(10) + chr(10) + "To: " + pmEmail.
NewEmailBody = NewEmailBody + chr(10) + "CC: " + cc.
**************/

NewEmailBody = NewEmailBody + "</pre></body></html>".

/* set Email Body */
ASSIGN Email-Text = NewEmailBody.

Looking back on that code, I see some things I should have done differently. Like I probably should have used the HTML break code “<br>” instead of CHR(10) (that’s an LF - line feed)

Hopefully that gives you an idea of how to build the email based on querying tables.

edit

@fmushi - I just now see you’re on E10. The above was for Vista/Vantage 8. I suggest starting a new topic in the E10 category. Also, a Method Directive (i.e. BPM) will be the way for you to go.