BPM Standard Data Directive on InvcHead requires multiple Invoices Check to send notifications

Hi all,
I’m currently working on a BPM (data directive standard) on InvcHead. When an invoice group is printed (printchecked flag is true), it checks if a customer contact with defined role code (in my case use “INVNT” value) and valid email address exists.

My problem is my code and directive only works on an invoice group with 1 invoice only. If the invoice group contains multiple invoices then it’s not going to run.

Any suggestions on how to loop through all the invoice numbers as needed? Not really having a coding background so it sounds a little bit tricky for me.

Erp.Tables.CustCnt CustCnt;
Erp.Tables.Customer Customer;
foreach (var ttInvcHead_iterator in (from ttInvcHead_Row in ttInvcHead
select ttInvcHead_Row))
{
var ttInvcHeadRow = ttInvcHead_iterator;
foreach (var Customer_iterator in (from Customer_Row in Db.Customer
where string.Compare(Customer_Row.Company, ttInvcHeadRow.Company, true) == 0
&& Customer_Row.CustNum == ttInvcHeadRow.CustNum
select Customer_Row))
{
Customer = Customer_iterator;
callContextBpmData.ShortChar01 = Customer.CustID;
callContextBpmData.Character02 = Customer.Name;
foreach (var CustCnt_iterator in (from CustCnt_Row in Db.CustCnt
where string.Compare(CustCnt_Row.Company, ttInvcHeadRow.Company, true) == 0
&& CustCnt_Row.CustNum == ttInvcHeadRow.CustNum && CustCnt_Row.RoleCode == “INVNT”
select CustCnt_Row))
{
CustCnt = CustCnt_iterator;
callContextBpmData.Character01 = CustCnt.EMailAddress;
}
}
}

Thanks,
Harry

The Data Directive should fire each time an InvcHead record is hit. So you shouldn’t need to loop through the invoices in the group. Just do the checks on the InvcHead being updated.

Tks, Calvin. I’ve added a condition if ttInvoiceNum change from any to another at the beginning of my above process but it didn’t work :frowning:

I might have misunderstood something. Is the ‘printchecked’ field on the InvcGrp table or the InvcHead?

I put it on InvcHead table. This Directive I’m creating on Erp.InvcHead.Update / Standard.

Do have Advanced Print Routing?

Excellent suggestion. I have made things too complicated by not using APR. Achieved my outcomes with APR instead of Data Directives.
Thank you very much, Calvin!