A year ago, I have to write a custom AIF service, where I have to extract All customer in Particular Legal Entity. For this purpose I have to create data Contract Classes and then these populate them and return from Service. The Customer Extraction on AIF will done on Customer Table level. But Address and Contact will be extracted from at DirPartyPostalAddressView and DirPartyContactInfoView
Code will be as follow.
List CustomerList; List addresses; List Contacts; CustomerDataContract objCust; CustAddressDataContract objCustAC; CustContactDataContract objCustCC; CustTable custtable; DirPartyPostalAddressView addressView; DirPartyContactInfoView contactView; DirPartyPrimaryContactInfoView partyprimaryView; int chunkSize = 10; while SELECT * FROM custtable { if(chunkSize >0) { objCust = new CustomerDataContract(); objCustAC = new CustAddressDataContract(); objCustCC = new CustContactDataContract(); objCust.parmAccountNum(custtable.AccountNum); objCust.parmCurrencyCode(custtable.Currency); //objCust.parmASNFlg(custtable. objCust.parmCustGroupId(custtable.CustGroup); objCust.parmOrganizationName(custtable.OrgId); objCust.parmInvoiceAccount(custtable.InvoiceAccount); objCust.parmCompanyChainId(custtable.CompanyChainId); objCust.parmPaymTermId (custtable.PaymTermId); objCust.parmPaymMode(custtable.PaymMode); objCust.parmCreditLimit(custtable.CreditMax); objCust.parmSiteId(custtable.InventSiteId); objCust.parmWarehouse(custtable.InventLocation); objCust.parmTaxGroup(custtable.TaxGroup); objCust.parmPriceGroup(custtable.PriceGroup); objCust.parmLineDisc(custtable.LineDisc); objCust.parmCountryId(custtable.PartyCountry); while SELECT * FROM addressView where addressView.Party == custtable.Party { objCustAC.parmStreet(addressView.Street); objCustAC.parmCity(addressView.City); objCustAC.parmState(addressView.state); objCustAC.parmZip(addressView.ZipCode); objCustAC.parmCountry(addressView.Address); objCustAC.parmAccountNum(vendtable.AccountNum); addresses.addEnd(objCustAC); } while SELECT * FROM contactView where contactView.Party == custtable.Party { objCustCC.parmAccountNum(custtable.AccountNum); objCustCC.parmContactType(contactView.Type); objCustCC.parmLocationName(contactView.LocationName); objCustCC.parmLocator(contactView.Locator); objCustCC.parmLocatorExtension(contactView.LocatorExtension); objCustCC.parmPrimary(contactView.IsPrimary); Contacts.addEnd(objCustCC); } objCust.parmAddresses(addresses); objCust.parmContacts(Contacts); vendorsList.addEnd(objCust); } chunkSize--; }