We are about to put this in place as well. Below is the alert program code we've come up with:
/* Send email whenever a Sales Order is taken off hold */
{ud/GlbAlert.i &TableName = "OrderHed"}
DEFINE VARIABLE NewEmailBody AS CHARACTER NO-UNDO.
DEFINE VARIABLE RepCode AS CHARACTER NO-UNDO.
DEFINE VARIABLE CustEmail AS CHARACTER NO-UNDO.
DEFINE VARIABLE RepEmail AS CHARACTER NO-UNDO.
ASSIGN RepCode = SUBSTRING((OrderHed.SalesRepList + "~~"), 1, INDEX((OrderHed.SalesRepList + "~~"),"~~") + -1).
FIND Customer WHERE Customer.Company = OrderHed.Company AND Customer.CustNum = OrderHed.BTCustNum NO-LOCK.
FIND OrderDtl WHERE OrderDtl.Company = OrderHed.Company AND OrderDtl.Ordernum = Orderhed.OrderNum NO-LOCK no-error.
FIND ShipTo WHERE ShipTo.Company = OrderHed.Company and ShipTo.CustNum = OrderHed.CustNum and ShipTo.ShipToNum = OrderHed.ShipToNum no-lock no-error.
FIND SalesRep WHERE SalesRep.Company = OrderHed.Company and SalesRep.SalesRepCode = RepCode no-lock no-error.
/* Don't send email if order is closed */
If NOT (orderhed.openorder) THEN DO:
RETURN "CANCEL SEND":U.
END.
/* Assign default customer email address in case the Customer and Ship-To don't have one */
ASSIGN CustEmail = "
cust_support@...".
IF Customer.EmailAddress NE "" THEN ASSIGN CustEmail = Customer.EmailAddress.
IF ShipTo.EmailAddress NE "" THEN ASSIGN CustEmail = ShipTo.EmailAddress.
/* Assign default rep email address in case the SalesRep doesn't have one */
ASSIGN RepEmail = "
cust_support@...".
IF SalesRep.EmailAddress NE "" THEN ASSIGN RepEmail = SalesRep.EmailAddress.
ASSIGN Email-To = CustEmail + "," +RepEmail.
ASSIGN Email-Subject = "New Sales Order# " + STRING(OrderHed.OrderNum).
/* Create the new body of the email */
ASSIGN NewEmailBody = "~n(Correct email addresses: Customer: " + STRING(CustEmail) + "~tRep: " + STRING(RepCode) + "~temail: " + STRING(RepEmail) + ")"
+ "~n~nDear Customer"
+ "~n~nWe have just entered a new sales order onto our system for you. The details are as follows:"
+ "~n~n Order Number: " + STRING(OrderHed.OrderNum)
+ "~n Order Date: " + STRING(Orderhed.OrderDate)
+ "~n Your PO Number: " + STRING(Orderhed.PONum)
+ "~n~n Bill to: " + STRING(Customer.Name) + ", " + STRING(Customer.Address1) + ", " + STRING(Customer.City) + ", " + STRING(Customer.State) + ", " + STRING(Customer.ZIP)
+ "~n Ship to: " + STRING(ShipTo.Name) + ", " + STRING(ShipTo.Address1) + ", " + STRING(ShipTo.City) + ", " + STRING(ShipTo.State) + ", " + STRING(ShipTo.ZIP)
+ "~n Expected Ship Date: " + (IF OrderHed.RequestDate = ? THEN "see below" ELSE STRING(orderhed.RequestDate)).
ASSIGN NewEmailBody = NewEmailBody
+ "~n~nIf you have any queries on this order please contact Customer Service, quoting the above order number, on:"
+ "~n Tel: (###) ### #### Fax: (###) ### #### Email:
sales@..."
+ "~n~n~nThank you,~n~nOur Company, Inc,~n123 Main St,~nNew York,~nNY 12345"
+ "~n~n~nDO NOT REPLY TO THIS E-MAIL ACCOUNT, IT DOES NOT GET REVIEWED!".
/* Lines of Order */
ASSIGN NewEmailBody = NewEmailBody
+ "~n~n~nOrder Lines:~n".
FOR EACH OrderDtl of OrderHed no-lock:
Assign NewEmailBody = NewEmailBody
+ " Item " + STRING(OrderDtl.OrderLine) + ":~t"
+ STRING(OrderDtl.PartNum) + " " + STRING(OrderDtl.LineDesc)
+ ":~t" + STRING(OrderDtl.OrderQty) + " piece(s)"
+ (IF OrderHed.RequestDate = ? THEN ":~tShip By: "
+ STRING(OrderDtl.RequestDate) ELSE "")
+ "~n".
END.
/* Print Email Body */
ASSIGN Email-Text = NewEmailBody
HTH,
Nigel.
--- In vantage@yahoogroups.com, "jesh1975" <jesh1975@...> wrote:
>
> Hello all,
>
> I want to create a BAM (Global alert) that will send e-mail once a new order is entered.Does anyone have any ideas on the simplest way to do this. Or does someone already have this done. version 8.04.408.
>
> Thanx
>