Business activity manager - send alert

thank you, pretty neat stuff.

--- In vantage@yahoogroups.com, "Brian W. Spolarich " <bspolarich@...> wrote:
>
> You can write your own 4GL program in which you can bring in any data you want. You save this as a .p file in your mfgsys803\server\ud folder, and set that as your custom alert program in the BAM definition.
>
> See my example below, based on suggestions from others here (Nigel Kerley in particular).
>
> I'm assuming that you'll need to reference the starting table that you're watching as the argument to GlbAlert.i in the first line, but from there you can invoke find queries to bring in data from related tables to your heart's content.
>
> The point of the program below is to send e-mail notifications to PO approvers and requestors so that notifications flow as you would expect them to, and the final disposition of the PO (approved or rejected) is reported back to the buyer who submitted the PO for approval.
>
> Its basic job is to set the special variables Email-To, Email-Cc, Email-From, Email-Subject, and Email-Text. These have the expected effects on the corresponding elements of the e-mail message that Vantage sends.
>
> You can also apparently send e-mail directly from within a BPM. Here's an example courtesy of Nathan Bonner. You'd need to deal with the variable assignments as appropriate, but you should get the idea. The point is to bring in the hEmailEx procedure from Bpm/BpmEmail, and then call SendEmail in hEmailEx with a bunch of arguments.
> -bws
>
> --
> Brian W. Spolarich ~ Manager, Information Services ~ Advanced Photonix / Picometrix
> Â Â Â Â bspolarich@... ~ 734-864-5618 ~ www.advancedphotonix.com
>
>
> -----Original Message-----
> From: vantage@yahoogroups.com [mailto:vantage@yahoogroups.com] On Behalf Of ppipaulz
> Sent: Wednesday, October 21, 2009 8:45 AM
> To: vantage@yahoogroups.com
> Subject: [Vantage] Business activity manager - send alert
>
> Is it just me or are BAM alerts very limited (Vantage 8.3.4)? I don't see where I could link two or more tables together to create a more useful rule on whether to send an alert or not. They seem to be limited to the one table you chose at the start, is there any alternatives to this when setting up alerts out of Vantage?
>
> -----BAM Example-----
>
> {ud/GlbAlert.i &TableName = "POHeader"}
>
> DEFINE VARIABLE POAmount AS DECIMAL NO-UNDO.
> DEFINE VARIABLE PONumber AS DECIMAL NO-UNDO.
> DEFINE VARIABLE Company AS CHARACTER NO-UNDO.
> DEFINE VARIABLE ApprovalStatus AS CHARACTER NO-UNDO.
> DEFINE VARIABLE ApproverEmail AS CHARACTER NO-UNDO.
> DEFINE VARIABLE ApproverName AS CHARACTER NO-UNDO.
> DEFINE VARIABLE ApproverCode AS CHARACTER NO-UNDO.
> DEFINE VARIABLE RequestorEmail AS CHARACTER NO-UNDO.
> DEFINE VARIABLE RequestorName AS CHARACTER NO-UNDO.
> DEFINE VARIABLE RequestorCode AS CHARACTER NO-UNDO.
> DEFINE VARIABLE StatusText AS CHARACTER NO-UNDO.
> DEFINE VARIABLE ApprovalStatusDesc AS CHARACTER NO-UNDO.
>
> PONumber = POHeader.PONum.
> Company = POHeader.Company.
> ApprovalStatus = POHeader.ApprovalStatus.
>
> message "In API-POApprovalNotification.p: Company: " + Company + " PONumber: " + string(PONumber) + " ApprovalStatus: " + ApprovalStatus + "~r~n".
>
> find PODetail where (PODetail.Company = POHeader.Company) and (PODetail.PONum = POHeader.PONum) no-lock no-error.
> for each PODetail of POHeader:
> POAmount = POAmount + (PODetail.DocUnitCost * PODetail.OrderQty).
> end.
>
> find POApvMsg where (POApvMsg.Company = POHeader.Company) and (POApvMsg.PONum = POHeader.PONum) no-lock no-error.
>
> if available POApvMsg then do:
>
> case POApvMsg.MsgType:
> when "1" then do:
> find PurAgent where (PurAgent.Company = POHeader.Company) and (PurAgent.BuyerId = POApvMsg.MsgTo) no-lock no-error.
> ApproverName = PurAgent.Name.
> ApproverEmail = PurAgent.EmailAddress.
> ApproverCode = PurAgent.BuyerID.
> find PurAgent where (PurAgent.Company = POHeader.Company) and (PurAgent.BuyerID = POApvMsg.MsgFrom) no-lock no-error.
> RequestorName = PurAgent.Name.
> RequestorEmail = PurAgent.EmailAddress.
> RequestorCode = PurAgent.BuyerID.
> end.
> when "2" then do:
> find PurAgent where (PurAgent.Company = POHeader.Company) and (PurAgent.BuyerId = POApvMsg.MsgTo) no-lock no-error.
> RequestorName = PurAgent.Name.
> RequestorEmail = PurAgent.EmailAddress.
> RequestorCode = PurAgent.BuyerID.
> find PurAgent where (PurAgent.Company = POHeader.Company) and (PurAgent.BuyerID = POApvMsg.MsgFrom) no-lock no-error.
> ApproverName = PurAgent.Name.
> ApproverEmail = PurAgent.EmailAddress.
> ApproverCode = PurAgent.BuyerID.
> end.
> end case.
>
>
> case ApprovalStatus:
> when "A" then do:
> StatusText = "Has Been Approved!".
> ApprovalStatusDesc = "Approved".
> Assign Email-To = RequestorEmail.
> end.
> when "R" then do:
> StatusText = "Has Been Denied!".
> ApprovalStatusDesc = "Rejected".
> Assign Email-To = RequestorEmail.
> end.
> when "P" then do:
> StatusText = "Requires Approval...".
> ApprovalStatusDesc = "Pending Approval".
> Assign Email-To = ApproverEmail.
> Assign Email-CC = RequestorEmail.
> end.
> when "U" then do:
> message "Not sending e-mail for ApprovalStatus = U".
> Assign SendEmail = False.
> end.
> end case.
>
> message "Email-To: " + Email-To + "~nEmail-CC: " + Email-CC.
>
> find Vendor where (Vendor.Company = POHeader.Company) and (Vendor.VendorNum = POHeader.VendorNum) no-lock no-error.
> Assign Email-From = "vantage-alerts@...".
> Assign Email-Subject = POHeader.Company + " Purchase Order Approval Status Notification".
> Assign Email-Text = "Purchase Order " + string(POHeader.PONum) + " " + StatusText + "~r~n"
> + "----------~r~n"
> + "Company: " + POHeader.Company + "~r~n"
> + "Vendor: " + Vendor.Name + " (" + Vendor.VendorID + ")~r~n"
> + "PO Amount: " + TRIM(string(POAmount, "$>>>,>>>,>>9.99")) + "~r~n"
> + "Approval Status: " + ApprovalStatusDesc + "~r~n"
> + "Buyer: " + RequestorName + " (" + RequestorCode + ") <" + RequestorEmail + ">~r~n"
> + "PO Date: " + string(POHeader.OrderDate) + "~r~n"
> + "Approver: " + ApproverName + " (" + ApproverCode + ") <" + ApproverEmail + ">~r~n"
> + "Comments: ~r~n" + POHeader.CommentText + "~r~n".
>
> if (POApvMsg.MsgText <> "") then do:
> Assign Email-Text = Email-Text + "Approval Message Log: ~r~n" + POApvMsg.MsgText + "~r~n".
> end.
> message "Email-Text: ~n" + Email-Text.
> end.
> else do:
> message "Not sending e-mail.~r~n".
> Assign SendEmail = False.
> return "Cancel Send".
> end.
>
> -----BPM Example-----
>
> define variable vFrom as character no-undo.
> define variable vTo as character no-undo.
> define variable vCC as character no-undo.
> define variable vSubject as character no-undo.
> define variable vBody as character no-undo.
> define variable hEmailEx as handle no-undo.
> run Bpm/BpmEmail.p persistent set hEmailEx.
>
> assign vFrom = 'vantage@...'.
> assign vTo = vPurAuth.
> assign vCC = vCC + string( ttPOHeader.EntryPerson + '@...').
> assign vSubject = vSubject + 'PO Num, ' + String(ttPOHeader.PONum) + ' is pending your approval'.
> assign vBody = vBody + String(ttPOHeader.PONum) + ' test'.
>
> run SendEmail in hEmailEx (
> false,
> CUR-COMP,
> vFrom,
> vTo,
> vCC,
> vSubject,
> vBody,
> String(ttPOHeader.PONum)
> ).
> if valid-handle(hEmailEx) then delete procedure hEmailEx.
> leave.
> end.
>
Is it just me or are BAM alerts very limited (Vantage 8.3.4)? I don't see where I could link two or more tables together to create a more useful rule on whether to send an alert or not. They seem to be limited to the one table you chose at the start, is there any alternatives to this when setting up alerts out of Vantage?

thanks
You can write your own 4GL program in which you can bring in any data you want. You save this as a .p file in your mfgsys803\server\ud folder, and set that as your custom alert program in the BAM definition.

See my example below, based on suggestions from others here (Nigel Kerley in particular).

I'm assuming that you'll need to reference the starting table that you're watching as the argument to GlbAlert.i in the first line, but from there you can invoke find queries to bring in data from related tables to your heart's content.

The point of the program below is to send e-mail notifications to PO approvers and requestors so that notifications flow as you would expect them to, and the final disposition of the PO (approved or rejected) is reported back to the buyer who submitted the PO for approval.

Its basic job is to set the special variables Email-To, Email-Cc, Email-From, Email-Subject, and Email-Text. These have the expected effects on the corresponding elements of the e-mail message that Vantage sends.

You can also apparently send e-mail directly from within a BPM. Here's an example courtesy of Nathan Bonner. You'd need to deal with the variable assignments as appropriate, but you should get the idea. The point is to bring in the hEmailEx procedure from Bpm/BpmEmail, and then call SendEmail in hEmailEx with a bunch of arguments.
-bws

--
Brian W. Spolarich ~ Manager, Information Services ~ Advanced Photonix / Picometrix
    bspolarich@... ~ 734-864-5618 ~ www.advancedphotonix.com


-----Original Message-----
From: vantage@yahoogroups.com [mailto:vantage@yahoogroups.com] On Behalf Of ppipaulz
Sent: Wednesday, October 21, 2009 8:45 AM
To: vantage@yahoogroups.com
Subject: [Vantage] Business activity manager - send alert

Is it just me or are BAM alerts very limited (Vantage 8.3.4)? I don't see where I could link two or more tables together to create a more useful rule on whether to send an alert or not. They seem to be limited to the one table you chose at the start, is there any alternatives to this when setting up alerts out of Vantage?

-----BAM Example-----

{ud/GlbAlert.i &TableName = "POHeader"}

DEFINE VARIABLE POAmount AS DECIMAL NO-UNDO.
DEFINE VARIABLE PONumber AS DECIMAL NO-UNDO.
DEFINE VARIABLE Company AS CHARACTER NO-UNDO.
DEFINE VARIABLE ApprovalStatus AS CHARACTER NO-UNDO.
DEFINE VARIABLE ApproverEmail AS CHARACTER NO-UNDO.
DEFINE VARIABLE ApproverName AS CHARACTER NO-UNDO.
DEFINE VARIABLE ApproverCode AS CHARACTER NO-UNDO.
DEFINE VARIABLE RequestorEmail AS CHARACTER NO-UNDO.
DEFINE VARIABLE RequestorName AS CHARACTER NO-UNDO.
DEFINE VARIABLE RequestorCode AS CHARACTER NO-UNDO.
DEFINE VARIABLE StatusText AS CHARACTER NO-UNDO.
DEFINE VARIABLE ApprovalStatusDesc AS CHARACTER NO-UNDO.

PONumber = POHeader.PONum.
Company = POHeader.Company.
ApprovalStatus = POHeader.ApprovalStatus.

message "In API-POApprovalNotification.p: Company: " + Company + " PONumber: " + string(PONumber) + " ApprovalStatus: " + ApprovalStatus + "~r~n".

find PODetail where (PODetail.Company = POHeader.Company) and (PODetail.PONum = POHeader.PONum) no-lock no-error.
for each PODetail of POHeader:
POAmount = POAmount + (PODetail.DocUnitCost * PODetail.OrderQty).
end.

find POApvMsg where (POApvMsg.Company = POHeader.Company) and (POApvMsg.PONum = POHeader.PONum) no-lock no-error.

if available POApvMsg then do:

case POApvMsg.MsgType:
when "1" then do:
find PurAgent where (PurAgent.Company = POHeader.Company) and (PurAgent.BuyerId = POApvMsg.MsgTo) no-lock no-error.
ApproverName = PurAgent.Name.
ApproverEmail = PurAgent.EmailAddress.
ApproverCode = PurAgent.BuyerID.
find PurAgent where (PurAgent.Company = POHeader.Company) and (PurAgent.BuyerID = POApvMsg.MsgFrom) no-lock no-error.
RequestorName = PurAgent.Name.
RequestorEmail = PurAgent.EmailAddress.
RequestorCode = PurAgent.BuyerID.
end.
when "2" then do:
find PurAgent where (PurAgent.Company = POHeader.Company) and (PurAgent.BuyerId = POApvMsg.MsgTo) no-lock no-error.
RequestorName = PurAgent.Name.
RequestorEmail = PurAgent.EmailAddress.
RequestorCode = PurAgent.BuyerID.
find PurAgent where (PurAgent.Company = POHeader.Company) and (PurAgent.BuyerID = POApvMsg.MsgFrom) no-lock no-error.
ApproverName = PurAgent.Name.
ApproverEmail = PurAgent.EmailAddress.
ApproverCode = PurAgent.BuyerID.
end.
end case.


case ApprovalStatus:
when "A" then do:
StatusText = "Has Been Approved!".
ApprovalStatusDesc = "Approved".
Assign Email-To = RequestorEmail.
end.
when "R" then do:
StatusText = "Has Been Denied!".
ApprovalStatusDesc = "Rejected".
Assign Email-To = RequestorEmail.
end.
when "P" then do:
StatusText = "Requires Approval...".
ApprovalStatusDesc = "Pending Approval".
Assign Email-To = ApproverEmail.
Assign Email-CC = RequestorEmail.
end.
when "U" then do:
message "Not sending e-mail for ApprovalStatus = U".
Assign SendEmail = False.
end.
end case.

message "Email-To: " + Email-To + "~nEmail-CC: " + Email-CC.

find Vendor where (Vendor.Company = POHeader.Company) and (Vendor.VendorNum = POHeader.VendorNum) no-lock no-error.
Assign Email-From = "vantage-alerts@...".
Assign Email-Subject = POHeader.Company + " Purchase Order Approval Status Notification".
Assign Email-Text = "Purchase Order " + string(POHeader.PONum) + " " + StatusText + "~r~n"
+ "----------~r~n"
+ "Company: " + POHeader.Company + "~r~n"
+ "Vendor: " + Vendor.Name + " (" + Vendor.VendorID + ")~r~n"
+ "PO Amount: " + TRIM(string(POAmount, "$>>>,>>>,>>9.99")) + "~r~n"
+ "Approval Status: " + ApprovalStatusDesc + "~r~n"
+ "Buyer: " + RequestorName + " (" + RequestorCode + ") <" + RequestorEmail + ">~r~n"
+ "PO Date: " + string(POHeader.OrderDate) + "~r~n"
+ "Approver: " + ApproverName + " (" + ApproverCode + ") <" + ApproverEmail + ">~r~n"
+ "Comments: ~r~n" + POHeader.CommentText + "~r~n".

if (POApvMsg.MsgText <> "") then do:
Assign Email-Text = Email-Text + "Approval Message Log: ~r~n" + POApvMsg.MsgText + "~r~n".
end.
message "Email-Text: ~n" + Email-Text.
end.
else do:
message "Not sending e-mail.~r~n".
Assign SendEmail = False.
return "Cancel Send".
end.

-----BPM Example-----

define variable vFrom as character no-undo.
define variable vTo as character no-undo.
define variable vCC as character no-undo.
define variable vSubject as character no-undo.
define variable vBody as character no-undo.
define variable hEmailEx as handle no-undo.
run Bpm/BpmEmail.p persistent set hEmailEx.

assign vFrom = 'vantage@...'.
assign vTo = vPurAuth.
assign vCC = vCC + string( ttPOHeader.EntryPerson + '@...').
assign vSubject = vSubject + 'PO Num, ' + String(ttPOHeader.PONum) + ' is pending your approval'.
assign vBody = vBody + String(ttPOHeader.PONum) + ' test'.

run SendEmail in hEmailEx (
false,
CUR-COMP,
vFrom,
vTo,
vCC,
vSubject,
vBody,
String(ttPOHeader.PONum)
).
if valid-handle(hEmailEx) then delete procedure hEmailEx.
leave.
end.