Home

Thursday, July 20, 2017

Find party Email phone and fax based on type ax 365

class TestRunnableClass
{      
    /// <summary>
    /// Runs the class with the specified arguments.
    /// </summary>
    /// <param name = "_args">The specified arguments.</param>
    public static void main(Args _args)
    {    
        /*LogisticsElectronicAddress      logisticsElectronicAddress;
        int64                           party;
        party                        = VendTable::find(PurchTable::find("P000000052").OrderAccount).Party;
        Phone ph=    LogisticsElectronicAddress::findPrimary( VendTable::find(PurchTable::find("P000000052").OrderAccount).Party, LogisticsElectronicAddressMethodType::Phone).Locator;
        info(strFmt("primary is --%1",ph));*/

     
        LogisticsElectronicAddress      logisticsElectronicAddress;
        VendTable vendtable;
        vendTable = VendTable::find("V000000020");
        select Location, Type, Locator,Description from logisticsElectronicAddress
        where logisticsElectronicAddress.Location == DirPartyLocation::findOrCreate(vendTable.Party, 0).Location
        && logisticsElectronicAddress.Type == LogisticsElectronicAddressMethodType::Email
        && logisticsElectronicAddress.IsPrimary == NoYes::Yes;
        info(strFmt("Email is-%1 .. Contact is-%2",logisticsElectronicAddress.Locator,logisticsElectronicAddress.Description));
           
       
    }

}

Ax 365 ssrs report handler class

class ABC_purchPurchaseOrderHandler
{
    
    
        /// <summary>
    ///
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    [DataEventHandler(tableStr(PurchPurchaseOrderHeader), DataEventType::Inserting)]
    public static void PurchPurchaseOrderHeader_onInserting(Common sender, DataEventArgs e)
    {
        PurchPurchaseOrderHeader    tmpTable = sender;
        VendTable                   vendTable;

        vendTable                        = VendTable::find(PurchTable::find(tmpTable.PurchId).OrderAccount);
        tmpTable.ABC_vendPhone           = PurchTable::find(tmpTable.PurchId).vendorPhone();
        tmpTable.ABC_vendTeleFax         = PurchTable::find(tmpTable.PurchId).vendTable_InvoiceAccount().telefax();
        tmpTable.ABC_DlvMode             = PurchTable::find(tmpTable.PurchId).DlvMode;
        tmpTable.ABC_PayTerms            = PurchTable::find(tmpTable.PurchId).Payment;
        tmpTable.ABC_SupplierDescription = PurchTable::find(tmpTable.PurchId).vendorName();
        tmpTable.ABC_Buyer               = HcmWorker::find(PurchTable::find(tmpTable.PurchId).WorkerPurchPlacer).name();
        tmpTable.ABC_InvoiceDescription  = dirParty::findPostalAddressByRole(vendTable.Party, LogisticsLocationRoleType::Invoice).displayLocationDescription();
        tmpTable.ABC_BillingAddress      = dirParty::findPostalAddressByRole(vendTable.Party, LogisticsLocationRoleType::Invoice).Address;
        tmpTable.ABC_Contact             = ABC_purchPurchaseOrderHandler::getContactDeatils(vendTable.Party, LogisticsElectronicAddressMethodType::Email).Description;
        tmpTable.ABC_vendPhone           = ABC_purchPurchaseOrderHandler::getContactDeatils(vendTable.Party, LogisticsElectronicAddressMethodType::Phone).Locator;
       
    }

    /// <summary>
    ///
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    [DataEventHandler(tableStr(PurchPurchaseOrderTmp), DataEventType::Inserting)]
    public static void PurchPurchaseOrderTmp_onInserting(Common sender, DataEventArgs e)
    {
        PurchPurchaseOrderTmp           tempTable = sender;
        VendPurchOrderJour              vendPurchOrderJour = VendPurchOrderJour::findRecId(tempTable.JournalRecId);
        CustVendExternalItem            custVendExternalItem;


        select ExternalItemTxt from custVendExternalItem
            where custVendExternalItem.ItemId == tempTable.ItemId &&
            custVendExternalItem.ExternalItemId == tempTable.ExternalItemNum &&
                custVendExternalItem.CustVendRelation == vendPurchOrderJour.purchTable().InvoiceAccount;

        tempTable.ABC_ExternalItemName  = custVendExternalItem.ExternalItemTxt;
    }

    /// <summary>
    /// Get the party contact details
    /// </summary>
    /// <param name = "_party"></param>
    /// <param name = "_type"></param>
    /// <returns></returns>
    public static LogisticsElectronicAddress getContactDeatils(RefRecId _party, LogisticsElectronicAddressMethodType _type)
    {
        LogisticsElectronicAddress      logisticsElectronicAddress;

        select * from logisticsElectronicAddress
            where logisticsElectronicAddress.Location == DirPartyLocation::findOrCreate(_party, 0).Location
                && logisticsElectronicAddress.Type == _type
                && logisticsElectronicAddress.IsPrimary == NoYes::Yes;

        return logisticsElectronicAddress;
    }

}