Works like a charm... Had tried a "Find Each..." but that wouldn't pass Validation but the "For Each..." as a secondary works great.
Final Code:
for each ttPOHeader no-lock , each PurAgent where (ttPOHeader.Company = PurAgent.Company and ttPOHeader.BuyerID = PurAgent.BuyerID) no-lock.
Define variable vPurAuth as character no-undo.
Assign vPurAuth = ''
for each PurAuth where (PurAgent.Company = PurAuth.Company and PurAgent.ApprovalPerson = PurAuth.BuyerID) no-lock .
/*If available PurAuth then do:*/
Assign vPurAuth = vPurAuth + PurAuth.DcdUserID + "@...; ".
End.
{lib\PublishInfoMsg.i &InfoMsg = "vPurAuth"}.
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.
Final Code:
for each ttPOHeader no-lock , each PurAgent where (ttPOHeader.Company = PurAgent.Company and ttPOHeader.BuyerID = PurAgent.BuyerID) no-lock.
Define variable vPurAuth as character no-undo.
Assign vPurAuth = ''
for each PurAuth where (PurAgent.Company = PurAuth.Company and PurAgent.ApprovalPerson = PurAuth.BuyerID) no-lock .
/*If available PurAuth then do:*/
Assign vPurAuth = vPurAuth + PurAuth.DcdUserID + "@...; ".
End.
{lib\PublishInfoMsg.i &InfoMsg = "vPurAuth"}.
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.
--- In vantage@yahoogroups.com, "bw2868bond" <bwalker@...> wrote:
>
> Couldn't you define vPurAuth as character initial value of ""
>
> Then where you want your loop
>
> for each PurAuth where (PurAgent.Company = PurAuth.Company and PurAgent.ApprovalPerson = PurAuth.BuyerID) no-lock .
> assign vPurAuth = vPurAuth + PurAuth.DcdUserID + "@...; ".
>
> end.
>
>
> (flying blind - not a 4gl expert)
>
>
> --- In vantage@yahoogroups.com, "bonner.nathan" <bonner.n@> wrote:
> >
> > Business Case:
> >
> > I need to send an email to the Approver of Purchase Orders whenever a PO needing their approval is generated.
> >
> > Current Approach:
> >
> > BPM on PO.Update
> >
> > Pre Process Condition triggering Post Process 4GL Action.
> >
> > Problem:
> >
> > Each Approver can have one or many Authorized Users.
> >
> > How do I get my code to loop through all the possible Authorized User records for a PO Approver? I am currently using the syntax that I know which give me only the First and Last records for Authorized Users and accumulating them in a defined variable, 'vPurAuth.' But I am sure there must be an array or 'do loop' function that will ensure that I get every Authoized User of the specified Approver.
> >
> > Current Code:
> >
> > for each ttPOHeader no-lock , each PurAgent where (ttPOHeader.Company = PurAgent.Company and ttPOHeader.BuyerID = PurAgent.BuyerID) no-lock.
> >
> > Define variable vPurAuth as character no-undo.
> >
> > /*Would like to start a loop here*/
> >
> > Find First PurAuth where (PurAgent.Company = PurAuth.Company and PurAgent.ApprovalPerson = PurAuth.BuyerID) no-lock .
> >
> > If available PurAuth then do:
> >
> > Assign vPurAuth = PurAuth.DcdUserID + "@...; ".
> >
> > End.
> >
> > Find Last PurAuth where (PurAgent.Company = PurAuth.Company and PurAgent.ApprovalPerson = PurAuth.BuyerID) no-lock .
> >
> > If available PurAuth then do:
> >
> > Assign vPurAuth = vPurAuth + PurAuth.DcdUserID + "@...; ".
> >
> > End.
> >
> > /*Would like to repeat or end a loop here*/
> >
> > {lib\PublishInfoMsg.i &InfoMsg = "vPurAuth"}.
> > /*Info message is for testing purposes only and will be removed prior to deployment to production*/
> >
> > 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.
> >
> > Thanks,
> >
> > NB
> >
>