Tuesday 31 March 2015

Mailing PO confirmation report in Ax 2012

PO confirmation report has to be sent mail once gets confirmed.
Default standard Ax will print the report using PurchPurchOrderJournalPrint,
to mail the report, the code has to written in the PurchPurchOrderJournalPrint,doPrint() method
as below
/// <summary>
/// Prints the document.
/// </summary>
protected void doPrint()
{
    this.printConfirmReport();
    this.sendmail(vendPurchOrderJour);

    vendPurchOrderJour.printJournal(this, journalList);
}

private void printConfirmReport()
{
    Args                        parameters = new Args();
    SRSPrintDestinationSettings printSettings;
    SrsReportRunController      controller = new SrsReportRunController();
    PurchPurchaseOrderContract  contract = new PurchPurchaseOrderContract();
    FILENAME                    filename;
    boolean                     newLine;
    Name                        filenamepath;
    ;
    newLine = journalList.first(vendPurchOrderJour);
    parameters.caller(this);
    if (journalList)
    {
        parameters.object(journalList);
    }
    controller.parmReportName(ssrsReportStr(PurchPurchaseOrder, Report));
    contract.parmRecordId(vendPurchOrderJour.RecId);
    contract.parmDocumentTitle("@SYS25545");
    controller.parmReportContract().parmRdpContract(contract);
    controller.parmShowDialog(false);
    printSettings = controller.parmReportContract().parmPrintSettings();
    printSettings.printMediumType(SRSPrintMediumType::File);
    printSettings.fileFormat(SRSReportFileFormat::PDF);
    printSettings.overwriteFile(true); 
    filenamepath = PurchParameters::find().PurchConfirmationFilepath;   
    filename = filenamepath + curext() + '_' +vendPurchOrderJour.PurchOrderDocNum + '.PDF';   
    printSettings.fileName(filename);
    controller.parmArgs(parameters);
    controller.startOperation();
}
private void IMX_sendmail(VendPurchOrderJour _vendPurchOrderJour)
{

SysMailer           mailer = new SysMailer();
SysEmailParameters  parameters = SysEmailParameters::find();
FilePath            filePath;
HcmWorker           hcmWorker;
PurchTable          purchTable;
Name                filename;
;
if (parameters.SMTPRelayServerName)
{
    mailer.SMTPRelayServer(parameters.SMTPRelayServerName,
                        parameters.SMTPPortNumber,
                        parameters.SMTPUserName,
                        SysEmailParameters::password(),
                        parameters.NTLM);
}
else
{
    mailer.SMTPRelayServer(parameters.SMTPServerIPAddress,
                            parameters.SMTPPortNumber,
                            parameters.SMTPUserName,
                            SysEmailParameters::password(),
                            parameters.NTLM);
}
filename = PurchParameters::find().PurchConfirmationFilepath;
purchTable  = PurchTable::find(_vendPurchOrderJour.PurchId);
hcmWorker   = HcmWorker::find(purchTable.Requester);
mailer.subject(_vendPurchOrderJour.PurchId);
mailer.fromAddress(DirPartyTable::findByName(UserInfoHelp::userName(curUserId())).primaryEmail());
mailer.htmlBody('Purchase Order confirmation of ' + _vendPurchOrderJour.PurchId +'.' + 'Please Find the Attachment.');
mailer.tos().appendAddress(hcmWorker.email());
mailer.tos().appendAddress(VendTable::find(purchTable.OrderAccount).email());
filePath = filename + curext() + '_' +vendPurchOrderJour.PurchOrderDocNum + '.PDF';
mailer.attachments().add(filePath);
mailer.sendMail();
CodeAccessPermission::revertAssert();
}

Correct me if am wrong....

Wednesday 25 March 2015

Copying Document Handling from one document to another document in Ax 2012

How to replicate the same document handling (File,Notes etc) from one document(Sales) to another document (Purchase).
Ex
If we want to show the Sales Document Handling Notes to Purchase Order, when we are creating direct delivery from Sales order to purchase order
then pass the following get the document handling

FromTable = salesTable;
ToTable     = purchTable;
Docu::copy(FromTable,ToTable);

Tuesday 24 March 2015

Selection Highlighter Extension for Ax 2012

Follow the below link to enhance your Ax client with Editor extension to have the following features in AX client as Visual Studio does.
1.Brace Matching Extension
2.highlight words Extension
3.Outlining Extension
Microsoft Dynamics AX 2012 X++ Editor Extensions 


Friday 20 March 2015

Job for container looping through Legal entity via X++, AX 2012

static void Containerloop(Args _args)
{
    int i;
    container   allLegalentity;
    str         con;

    allLegalentity = conNull();
    allLegalentity = ['USMF','JPMF','INMF'];

    while (conLen(allLegalentity) > 0)

    {
        i++;
        con = conPeek(allLegalentity,i);

        changeCompany(con)
        {
            // code statement
            info(strFmt("%1)  %2",i,con));

        }

        if (i >= conLen(allLegalentity))
        break;
    }

}

Wednesday 4 March 2015

Getting exchange rate value in ax 2012

public static CurrencyExchangeRate currencyConversion(CurrencyCode fromCurrencyCode, CurrencyCode toCurrencyCode)
{
    ExchangeRateCurrencyPair exchangeRateCurrencyPair,exchangeRateCurrencyPair2;
    ExchangeRateDisplayFactor exchangeRateDisplayFactor;
    ExchangeRate exchangeRate;
    date validFromDate = dateNull();
    date validToDate = dateMax();


    CurrencyCode _fromCurrencyCode =  fromCurrencyCode;
    CurrencyCode _toCurrencyCode = toCurrencyCode;
    ExchangeRateTypeRecId _exchangeRateType2;
    boolean _getReciprocalIfPrimaryNotFound = true;

    CurrencyExchangeRate exchRateValue;

    _exchangeRateType2 = ExchangeRateType::findByName(Exchange Rate Type).RecId;


    select firstonly ExchangeRateDisplayFactor
        from exchangeRateCurrencyPair
        where exchangeRateCurrencyPair.FromCurrencyCode == _fromCurrencyCode
            && exchangeRateCurrencyPair.ToCurrencyCode == _toCurrencyCode
            && exchangeRateCurrencyPair.ExchangeRateType == _exchangeRateType2;
    if(exchangeRateCurrencyPair.ExchangeRateDisplayFactor)
    {

        select firstonly validtimestate(validFromDate, validToDate) exchangeRate
        where
        exchangeRate.ExchangeRateCurrencyPair == exchangeRateCurrencyPair.RecId;
        exchRateValue = ExchangeRateHelper::displayStoredExchangeRate_Static(
                exchangeRate.ExchangeRate,
                exchangeRateCurrencyPair.ExchangeRateDisplayFactor);
    }
    else
    {
       select firstonly ExchangeRateDisplayFactor
        from exchangeRateCurrencyPair2
        where exchangeRateCurrencyPair2.FromCurrencyCode == _toCurrencyCode
            && exchangeRateCurrencyPair2.ToCurrencyCode == _fromCurrencyCode
            && exchangeRateCurrencyPair2.ExchangeRateType == _exchangeRateType2;

        if(exchangeRateCurrencyPair2.exchangeRateDisplayFactor)
        {
            select firstonly validtimestate(validFromDate, validToDate) exchangeRate
            where exchangeRate.ExchangeRateCurrencyPair == exchangeRateCurrencyPair2.RecId;

            exchRateValue = exchangeRateCurrencyPair2.ExchangeRateDisplayFactor / ExchangeRateHelper::displayStoredExchangeRate_Static(
                exchangeRate.ExchangeRate,
                exchangeRateCurrencyPair2.ExchangeRateDisplayFactor);
        }
    }
    return exchRateValue;
}

Getting Availablephysical for item based on financial Dimension site in Ax 2012

public InventQty getavailablephysicalqty(ItemId _itemId, DimensionDefault _defualtDimension)
{
    InventSum                       inventSum;
    DefaultDimensionView            defaultDimensionView;
    DimensionAttributeValueSetItem  dimensionAttributeValueSetItem;
    DimensionAttributeValueSet      dimensionAttributeValueSet;
    InventSite                      inventSite;
    InventDim                       inventDimtemp,inventDimdummy;

    select firstonly DisplayValue from defaultDimensionView
        where defaultDimensionView.DefaultDimension == _defualtDimension
        && defaultDimensionView.Name == 'CostCenterSYS';

    select DimensionAttributeValueSet from dimensionAttributeValueSetItem
        where dimensionAttributeValueSetItem.DisplayValue == defaultDimensionView.DisplayValue
    join dimensionAttributeValueSet
        where dimensionAttributeValueSet.RecId  == dimensionAttributeValueSetItem.DimensionAttributeValueSet
    join SiteId from inventSite
        where inventSite.DefaultDimension == dimensionAttributeValueSet.RecId;

    inventDimtemp.InventLocationId  = "";
    inventDimtemp.InventColorId     = "";
    inventDimtemp.InventSizeId      = "";
    inventDimtemp.inventBatchId     = "";
    inventDimtemp.InventStyleId     = "";
    inventDimtemp.inventSerialId    = "";
    inventDimtemp.InventSiteId      = inventSite.SiteId;

    inventDimdummy = InventDim::findOrCreate(inventDimtemp);
    inventDimdummy = null;
   
     select PhysicalInvent from inventSum
         exists join inventDimdummy
            where inventSum.ItemId == _itemId
               && inventSum.Closed == NoYes::No     
               && inventSum.InventDimId == inventDimdummy.inventDimId
               && inventDimdummy.InventSiteId == inventSite.SiteId;

    return inventSum.PhysicalInvent;
}

Calculate ledger balance by dimension set in X++ in AX2012/Dynamics 365 FO

There are a variety of ways users can view balances in the general ledger. Some of the most common options are: 1. Trial balance 2. Financia...