Monday, 29 February 2016

Get Email/ Phone from Cust table

https://rahulmsdax.blogspot.com/2019/10/sql-queries-to-get-customers-and-vendor.html

Find Electronic Address of Party : 

// Get LogisticsElectronicAddress from Vendtable  and get contact details.

VendTable vendtable;
            DirPartyLocation dirPartyLocation;

            select * from vendTable
                join dirPartyLocation where vendTable.Party == dirPartyLocation.Party
                    join logisticsElectronicAddress where logisticsElectronicAddress.Location == dirPartyLocation.Location
                 && logisticsElectronicAddress.ElectronicAddressRoles == "Purchase order"
                 && logisticsElectronicAddress.type == LogisticsElectronicAddressMethodType::Phone
            && logisticsElectronicAddress.IsPrimary == NoYes::Yes
                && VendTable.AccountNum == purchPurchaseOrderHeader.TRI_VendorAccount;
         
            //contactname               =   logisticsElectronicAddress.Locator;
            contactname               =   logisticsElectronicAddress.Locator;

========================================================================

//Get Phone no attached to address

RecId LocationRecId = LogisticsPostalAddress::findRecId(_shipmentTable.DeliveryPostalAddress).Location;
        RecId logisticselectronicAddrRecId = LogisticsLocation::findElectronicLocationByParent(LocationRecId).RecId;

        logisticsElectronicAddress  logisticsElectronicAddress;
        select firstonly logisticsElectronicAddress
            where logisticsElectronicAddress.Locator != ""
            && logisticsElectronicAddress.type == LogisticsElectronicAddressMethodType::Phone
            && logisticselectronicAddrRecId== logisticsElectronicAddress.Location
        && logisticsElectronicAddress.IsPrimary == NoYes::Yes;

        if(!logisticsElectronicAddress)
        {
            select firstonly logisticsElectronicAddress
            where logisticsElectronicAddress.Locator != ""
            && logisticsElectronicAddress.type == LogisticsElectronicAddressMethodType::Phone
            && logisticselectronicAddrRecId== logisticsElectronicAddress.Location
            && logisticsElectronicAddress.IsPrimary == NoYes::No;
        }
        packinglistTmp.ShipTo               =   _shipmentTable.displayDropOffLoc()+'\n'+logisticsElectronicAddress.Locator;


// Get phone no attached to address. not primay.

        CustTable custtable = CustTable::find(_salesTable.InvoiceAccount);
        Addressing                  address;
        DirPartyRecId               party;
        LogisticsPostalAddress      postalAddressloc;
        logisticsElectronicAddress  logisticsElectronicAddressloc;
        DirPartyLocation            dirPartyLocation;
        select * from logisticsElectronicAddressloc
            join dirPartyLocation
           where dirPartyLocation.Party    == custtable.Party &&
                 dirPartyLocation.Location == logisticsElectronicAddressloc.Location &&
            logisticsElectronicAddressloc.Type == LogisticsElectronicAddressMethodType::Phone;

        packinglistTmp.BillTo               =  custtable.address()+'\n'+logisticsElectronicAddressloc.Locator; 



FieldId primaryFieldId = DirPartyTable::electronicAddressType2primaryFieldId(LogisticsElectronicAddressMethodType::Email);

//Get Primary

select firstonly logisticsElectronicAddress
join dirPartyTable
where logisticsElectronicAddress.Locator != ”
&& logisticsElectronicAddress.type == LogisticsElectronicAddressMethodType::Email
&& dirPartyTable.(primaryFieldId) == logisticsElectronicAddress.RecId
&& dirPartyTable.RecId == custTable.Party;

salesTable.Email = logisticsElectronicAddress.Locator;
if(!logisticsElectronicAddress.Locator)
{

//Get other email
select firstonly logisticsElectronicAddress
join Party,Location from dirPartyLocation
where logisticsElectronicAddress.Locator != ”
&& logisticsElectronicAddress.type == LogisticsElectronicAddressMethodType::Email
&& dirPartyLocation.Party == custTable.Party
&& logisticsElectronicAddress.Location == dirPartyLocation.Location;

salesTable.Email = logisticsElectronicAddress.Locator;
if(!salesTable.Email)
salesTable.Email = custEmail;

==============================================================
For Phone :


FieldId primaryFieldId = DirPartyTable::electronicAddressType2primaryFieldId(LogisticsElectronicAddressMethodType::Phone);

//Get Primary

select firstonly logisticsElectronicAddress
join dirPartyTable
where logisticsElectronicAddress.Locator != ”
&& logisticsElectronicAddress.type == LogisticsElectronicAddressMethodType::Phone
&& dirPartyTable.(primaryFieldId) == logisticsElectronicAddress.RecId
&& dirPartyTable.RecId == custTable.Party;

salesTable.Email = logisticsElectronicAddress.Locator

No comments:

Post a Comment