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, ">", ">").
s = REPLACE(s, "<", "<").
s = REPLACE(s, CHR(49833), "©").
s = REPLACE(s, CHR(49838), "®").
s = REPLACE(s, CHR(14844060),CHR(34)).
s = REPLACE(s, CHR(14844061),CHR(34)).
s = REPLACE(s, CHR(14845090), "™").
s = REPLACE(s, CHR(14844588), "€").
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.