Monday, June 22, 2015

How to get contact's email addresses from a customer or vendor

How to get  customer email addresses from all contacts associated with a customer from Company/Accounts receivable/Common/Customers/All customers/Contacts/Contact Info



Method exists on \Tables\CustTable

public container getInvoiceContacts()
{
    container invoiceEmailAddresses;
    DirPartyTable dirParty;
    LogisticsElectronicAddress electronicAddress;
    DirPartyLocation dirPartyLoc;
    ContactPerson contactPerson;
   
//find all of the customer contact email addresses that are currently active  
 while select * from contactPerson
        where contactPerson.CustAccount == this.AccountNum && contactPerson.Inactive == NoYes::No
        join  RecId from dirParty
        where dirParty.RecId == contactPerson.Party
        join Location, Type, SendInvoice, Locator FROM electronicAddress
         EXISTS JOIN Location, Party FROM dirPartyLoc
        WHERE electronicAddress.Location == dirPartyLoc.Location && dirParty.RecId==dirPartyLoc.Party
            && electronicAddress.Type == LogisticsElectronicAddressMethodType::Email
    {
        invoiceEmailAddresses += electronicAddress.Locator;
    }
    return invoiceEmailAddresses;
}



How to get vendor email addresses from all contacts associated with a vendor  from Company/Accounts payable/Common/Vendors/All vendors/Contacts/Contact Info

Method exists on \Tables\VendTable

public container getRemittanceContacts()
{
    container remittanceEmailAddresses;
    DirPartyTable dirParty;
    LogisticsElectronicAddress electronicAddress;
    DirPartyLocation dirPartyLoc;
    ContactPerson contactPerson;
   
//find all of the vendor contact email addresses that are currently active  
while select * from contactPerson
        where contactPerson.ContactForParty == this.Party && contactPerson.Inactive == NoYes::No
        join  RecId from dirParty
        where dirParty.RecId == contactPerson.Party
        join Location, Type, SendRemittance, Locator FROM electronicAddress
         EXISTS JOIN Location, Party FROM dirPartyLoc
        WHERE electronicAddress.Location == dirPartyLoc.Location && dirParty.RecId==dirPartyLoc.Party
            && electronicAddress.Type == LogisticsElectronicAddressMethodType::Email
    {
        remittanceEmailAddresses += electronicAddress.Locator;
    }
    return remittanceEmailAddresses;
}


As you can see customer & vendors operate pretty much the same except for the association of custaccount(customer) vs contactforparty(vendor) on the contactperson table.

I'm posting this since AX seems to love to use the view "DirPartyPostalAddressView" as the main listing for these contacts on the form. So it can take a little while of digging to discover the true relationship between these tables.

No comments:

Post a Comment