More Parent Info

Vantage 8.03.407a

I spent a day on this so I thought I would share it in case someone else finds it usefull.

I hate the parent child setup in Vantage. The only information in the Customer table is the ParentCustNum. This makes reports and dashboards difficult to write for a parent child relationship. So I decided to put the parent's custID and name into ShortChar06 & ShortChar07 UD Fields of the Customer Table. I experimented with Customizaions and BPMs, but could never get them to work in all situations.

I finaly came up with the idea of useing a BAM. I set up my BAM for the Customer Table and selected the ParentCustNum field, no rules, and the action is "Send Alert" with nothing filled out except for the alert program called "Update Customer Parent Info.p". The alert program is listed below. It doesn't send an email, just updates ShortChar06 & ShortChar07. If the customer is not a child, then it gets it's own ID and name in these fields.

/* Assign the include file */
{ud/GlbAlert.i &TableName = "Customer"}

Define BUFFER ParentCustomer FOR Customer.
Define Variable CustomerNumber as Integer NO-UNDO.
Define Variable CustomerID as Character NO-UNDO.
Define Variable CustomerName as Character NO-UNDO.
Define Variable Company as Character NO-UNDO.
Define Variable ParentCustomerNumber as Integer NO-UNDO.

CustomerNumber = Customer.CustNum.
CustomerID = Customer.CustID.
CustomerName = Customer.Name.
Company = Customer.Company.
ParentCustomerNumber = Customer.ParentCustNum.

If Customer.ParentCustNum = 0 Then Do:
/* Update UD Fields if there is no parent */
Run lib\UpdateTableBuffer.p(input BUFFER Customer:HANDLE, 'ShortChar06', Customer.CustID).
Run lib\UpdateTableBuffer.p(input BUFFER Customer:HANDLE, 'ShortChar07', Customer.Name).
End.
Else Do:
/* Find Parent Customer */
Find First ParentCustomer Where (ParentCustomer.Company = Company) and (ParentCustomer.CustNum = ParentCustomerNumber) NO-LOCK.
CustomerID = ParentCustomer.CustID.
CustomerName = ParentCustomer.Name.
/* Update UD Fields in Child Customer Table */
Run lib\UpdateTableBuffer.p(input BUFFER Customer:HANDLE, 'ShortChar06', CustomerID).
Run lib\UpdateTableBuffer.p(input BUFFER Customer:HANDLE, 'ShortChar07', CustomerName).
End.
RETURN "CANCEL SEND":U.