adsenseheader

Thursday, December 12, 2019

AOD flush in D365 for operations

HI,

Below post shall help you in clearing the AOD flush

// Class to clear the cache, build a URL to call it:

https://[AOS NAME].cloudax.dynamics.com/?mi=SysClassRunner&cls=SysFlushAOD

or

https://[AOS NAME].cloudax.dynamics.com/?mi=action:SysFlushAOD

Regards,
Pradeep

Monday, November 18, 2019

Create Ledger dimension only with MainAccount in AX 365 for operations

HI,

The below code shall help you to create a Ledger Dimension through MainAccountNum in 365 for operations.


LedgerDimensionFacade::serviceCreateLedgerDimension(
            LedgerDefaultAccountHelper::getDefaultAccountFromMainAccountRecId(
                MainAccount::findByMainAccountId(_mainAccountId).RecId),
            0);

Regards,
Pradeep

Monday, November 4, 2019

Additional voucher creation for an Procurement item, Correct and Cancel Product receipt for Purchase Order in D365 for opeartions

Hi Guys,

Below code shall help in  creating additional Vouchers for a Procurement item and also correcting and canceling the Product receipt.

Distributes amount based on the Accounting distribution setup on the Purchase order line


[ExtensionOf(classStr(PurchPackingSlipJournalPost))]
final class ABC_PurchPackingSlipJournalPost_Extension
{
    protected void postSingleLine(boolean _countryRegion_RU,
                                  boolean _hasQualityOrder,
                                  boolean _isExciseEnableIN,
                                  boolean _isVATEnableIN,
                                  boolean _isCustomsEnableIN,
                                  boolean _isConfigurationkeyRetailEnabled)
    {
        LedgerDimensionAccount          ledgerDimensionId;
        AccountingDistribution          accountingDistribution;
        LedgerDimensionDefaultAccount   ledgerDefaultAccount;
        LedgerDimensionDefaultAccount   ledgerDefaultAccountOffset;
        DimensionDefault                defaultDim;
        Amount                          gstAmount;
        Amount                          creditAmount;
        Amount                          debitAmount;
        LedgerVoucher                   ledgerVoucher;
        LedgerVoucherTransObject        ledgerVoucherTransObject;
        CurrencyCode                    standardCurrencyCode;
        LedgerVoucherObject             ledgerVoucherObject;
        CurrencyExchangeHelper          currencyExchHelper;

        xyz_POItemFeeTable              POItemFeeTable;
        PurchLine                       purchLineLocal = this.sourceLine();

        next postSingleline (_countryRegion_RU,     _hasQualityOrder, _isExciseEnableIN, _isVATEnableIN, _isCustomsEnableIN,  _isConfigurationkeyRetailEnabled);

        PurchParmLine                   purchParmLine = this.purchParmLine;
        PurchParmLine                   purchParmLineloc = this.purchParmLine;
        SourceDocumentLine              sourceDocumentLine;
        Qty                             res = purchParmLineloc.purchQtyCorrection();
        AccountingDistribution          accDist;
        AccountingDistribution          revAccDist;
        SourceDocumentLine              sourceDocLine;
        PurchTable                      purchTable = PurchTable::find(purchline.PurchId);
        AllocationFactor                allocationFactor;

        while select forupdate RecId from sourceDocLine
                where
                    sourceDocLine.SourceDocumentHeader == purchTable.SourceDocumentHeader
            join forupdate accDist
                where
                    accDist.SourceDocumentLine == sourceDocLine.RecId &&
                    accDist.ReferenceRole != AccountingDistributionReferenceRole::Reversing
            notexists join revAccDist
                where
                    (   revAccDist.ReferenceDistribution == accDist.RecId &&
                        revAccDist.SourceDocumentLine == sourceDocLine.RecId &&
                        revAccDist.ReferenceRole == AccountingDistributionReferenceRole::Reversing
                    )
                    ||
                    (
                        revAccDist.ReferenceDistribution == accDist.RecId &&
                        revAccDist.SourceDocumentLine == sourceDocLine.RecId &&
                        revAccDist.ReferenceRole == AccountingDistributionReferenceRole::Adjusting
                    )
        {
            if (accDist.AllocationFactor == 1.0)
            {
                continue;
            }

            allocationFactor += accDist.AllocationFactor;
         
            if (purchLineLocal.ProcCatRecoverable_xyz== NoYes::Yes)
            {
                Amount exclGst =   xyz_ItemFeeTable::findByPurchLine(purchLineLocal.recId).RecoveryAmountExclGST;
                if (this.versioningUpdateType == VersioningUpdateType::Correction)
                {
                    gstAmount = ((exclGst /purchLineLocal.PurchQty ) * res) * accDist.AllocationFactor;
                    creditAmount = -decRound(gstAmount,2);
                    debitAmount  = creditAmount * -1;
                }

                else if (this.versioningUpdateType == VersioningUpdateType::Cancel)
                {
                    gstAmount = xyz_ItemFeeTable::findByPurchLine(purchLineLocal.recId).RecoveryAmountExclGST / purchLineLocal.PurchQty;
                    creditAmount = -(gstAmount * res) * accDist.AllocationFactor;
                    creditAmount = decRound(creditAmount,2);
                    debitAmount  = creditAmount * -1;
                }
                else
                {
                    gstAmount = 0 ;
                    creditAmount = ((xyz_ItemFeeTable::findByPurchLine(purchLineLocal.recId).RecoveryAmountExclGST /purchLineLocal.PurchQty ) * purchParmLineloc.ReceiveNow) * accDist.AllocationFactor  ;
                    creditAmount = decRound(creditAmount,2);
                    debitAmount  = -creditAmount;
                }
         

                ledgerDefaultAccount = InventPosting::accountItemLedgerDimensionFromParameters(InventPostingAccountItemLedgerDimensionParameters::newFromParameters(
                                                                                        InventAccountType::RevenueAccrual_xyz,
                                                                                        purchLineLocal.ItemId,
                                                                                        purchLineLocal.inventTable().itemGroupId(),
                                                                                        purchLineLocal.ProcurementCategory,
                                                                                        purchLineLocal.VendAccount,
                                                                                        purchLineLocal.VendGroup,
                                                                                        purchLineLocal.TaxGroup
                                                                                        ));
                ledgerDimensionId = LedgerDimensionFacade::serviceCreateLedgerDimension(ledgerDefaultAccount);

                ledgerVoucher = this.ledgerVoucher;
         
                ledgerVoucherObject = this.findOrCreateLedgerVoucherObject(this.getVoucher(), this.updateDate());
         
                standardCurrencyCode = CompanyInfoHelper::standardCurrency();
                currencyExchHelper = CurrencyExchangeHelper::newExchangeDate(Ledger::current(), systemDateGet());

                ledgerVoucherTransObject =  LedgerVoucherTransObject::newTransactionAmountDefault(ledgerVoucherObject  ,
                                                                                                    LedgerPostingType::RevenueAccrual_xyz,
                                                                                                    ledgerDimensionId,
                                                                                                    standardCurrencyCode,
                                                                                                    debitAmount,
                                                                                                    currencyExchHelper);

                ledgerVoucher.addTrans(ledgerVoucherTransObject);

                //for credit account
                ledgerDefaultAccount = InventPosting::accountItemLedgerDimensionFromParameters(InventPostingAccountItemLedgerDimensionParameters::newFromParameters(
                                                                                        InventAccountType::RevenuePurchReceipt_xyz,
                                                                                        purchLineLocal.ItemId,
                                                                                        purchLineLocal.inventTable().itemGroupId(),
                                                                                        purchLineLocal.ProcurementCategory,
                                                                                        purchLineLocal.VendAccount,
                                                                                        purchLineLocal.VendGroup,
                                                                                        purchLineLocal.TaxGroup
                                                                                        ));

                defaultDim = LedgerDimensionFacade::getDefaultDimensionFromLedgerDimension(accDist.ledgerdimension);

                ledgerDimensionId = LedgerDimensionFacade::serviceCreateLedgerDimension(ledgerDefaultAccount);
                ledgerDefaultAccountOffset = LedgerDimensionFacade::serviceMergeLedgerDimensions(ledgerDimensionId,accDist.ledgerdimension);
                ledgerVoucherTransObject =  LedgerVoucherTransObject::newTransactionAmountDefault(ledgerVoucherObject,
                                                                                                    LedgerPostingType::RevenuePurchReceipt_xyz,
                                                                                                    ledgerDefaultAccountOffset,
                                                                                                    standardCurrencyCode,
                                                                                                    creditAmount,
                                                                                                    currencyExchHelper);
                ledgerVoucherObject.addTrans(ledgerVoucherTransObject);
                ledgerVoucherObject.parmVoucherCheck(false);
            }

            if (allocationFactor == 1.0)
            {
                break ;
            }
        }
    }

}


Thanks,
Pradeep

Get Ledger dimension account from Invent posting profile

HI Guys,

Below code shall help in fetching the right account and create a ledgerDimension for the same from the InventPosting profile.

public InventPostingAccountItemLedgerDimensionParameters buildAccountItemLedgerDimensionParameter(PurchLine       _purchLine)
    {
        return InventPostingAccountItemLedgerDimensionParameters::newFromParameters(
                                                                                    InventAccountType::RevenueAccrual_xyz,
                                                                                    _purchLine.ItemId,
                                                                                    _purchLine.inventTable().itemGroupId(),
                                                                                    _purchLine.ProcurementCategory,
                                                                                    _purchLine.VendAccount,
                                                                                    _purchLine.VendGroup,
                                                                                    _purchLine.TaxGroup
                                                                                    );
    }

Thanks,
Pradeep

Get Accounting distribution for Purchase order line in AX for D365 for operations

Hi Guys,

The below code shall help you in pulling Account Distribution allocation factors between the Customer for a PurchaseOrder line.

while select forupdate RecId from sourceDocLine
                where
                    sourceDocLine.SourceDocumentHeader == purchTable.SourceDocumentHeader
            join forupdate accDist
                where
                    accDist.SourceDocumentLine == sourceDocLine.RecId &&
                    accDist.ReferenceRole != AccountingDistributionReferenceRole::Reversing
            notexists join revAccDist
                where
                    (   revAccDist.ReferenceDistribution == accDist.RecId &&
                        revAccDist.SourceDocumentLine == sourceDocLine.RecId &&
                        revAccDist.ReferenceRole == AccountingDistributionReferenceRole::Reversing
                    )
                    ||
                    (
                        revAccDist.ReferenceDistribution == accDist.RecId &&
                        revAccDist.SourceDocumentLine == sourceDocLine.RecId &&
                        revAccDist.ReferenceRole == AccountingDistributionReferenceRole::Adjusting
                    )
        {
            if (accDist.AllocationFactor == 1.0)
            {
                continue;
            }

            allocationFactor += accDist.AllocationFactor;

            // Write the your business logic her based on the allocation factor
Note: the First loop would always result with allocation factor 1

            if (allocationFactor == 1.0)
            {
                break ;
            }


Hope this help you

Thanks,
Pradeep

Thursday, October 31, 2019

Get Packing Slip Journal from Invoice Journal In Dynamics AX 365 for Operations

Hi,

The below code would help you in getting details of the Packing slip journal from the Invoice Journal.

static void getPackingSlip(Args _args)
{
    CustInvoiceJour     custInvoiceJour;
    SalesParmTable      salesParmTable;
    CustPackingSlipJour custPackingSlipJour;
    SalesParmSubLine    salesParmSubLine;
    SalesParmLine       salesParmLine;

    custInvoiceJour = CustInvoiceJour::findRecId(35637193385);
    select firstOnly salesParmTable
        where salesParmTable.ParmId == custInvoiceJour.ParmId
            && salesParmTable.Ordering == DocumentStatus::Invoice;

    //in case of multiple packing slip selected in invoice
    while select DocumentId from salesParmSubLine
            exists join salesParmLine
            where salesParmSubLine.LineRefRecId == salesParmLine.RecId
                && salesParmLine.ParmId          == salesParmTable.ParmId
                && salesParmLine.TableRefId      == salesParmTable.TableRefId
    {
        select firstOnly custPackingSlipJour
            where custPackingSlipJour.PackingSlipId == salesParmSubLine.DocumentId
                && custPackingSlipJour.SalesId == salesParmTable.SalesId;
        info(strFmt("%1-%2-%3-%4",custPackingSlipJour.DeliveryDate,custPackingSlipJour.PackingSlipId,salesParmTable.SalesId,custInvoiceJour.InvoiceId));
    }
   // info(strFmt("%1",salesParmTable.packingSlipId(salesParmTable)));
}

Thanks & Regards,
Pradeep

Tuesday, October 29, 2019

Add additional report designs on your Print management

HI,

If you are trying to find a way to populate your new report design on the print management form.

Please find the below steps.

1. Create a delegate of  your print management class "PrintMgmtDocType" method "getDefaultReportFormatDelegate"
2. Below code to add your new design

class QTQ_ProjInvcPrintMgmtDocTypeHandlers
{
    [SubscribesTo(classstr(PrintMgmtDocType), delegatestr(PrintMgmtDocType, getDefaultReportFormatDelegate))]
    public static void getDefaultReportFormatDelegate(PrintMgmtDocumentType _docType, EventHandlerResult _result)
    {
        switch (_docType)
        {
            case PrintMgmtDocumentType::SIProjInvoice:
            case PrintMgmtDocumentType::SIProjInvoiceWithBR:
if (curExt() == 'CRRO' || curext() == 'CRBG')
                {
                    _result.result(ssrsReportStr(QTQ_PSAPojInvoice, Report));
                }
else
                {
                    _result.result(ssrsReportStr(QTQ_PSAPojInvoice, Report_Standard));
                }
                break;
        }
    }

}

3. Now build the class, you can see your new report design under Fomsetup --> Print Management --> Report design











Thanks,
Pradeep


Wednesday, October 16, 2019

Make a text BOLD through expression in SSRS reports

Hi,

With the below steps you can concatenate Label and Field value and make only Label bold with the expressions as detailed below.

Step 1:

Go to Text box --> Expression










Step 2:

Go the expression properties (Double click on the Textbox expression) and select HTML


Tuesday, October 15, 2019

File upload and export data to excel

Hi,

Below code would be helpful to upload a file in Dynamics 365 for operations and take necessity actions on the data from the file.

Export the result to an excel file

class ReadAndExportData
{     
    NoYesId printOut;
    NoYesId deleteInventTransId;
    FileUploadTemporaryStorageResult fileVal;

    public NoYesId parmPrintOut(NoYesId _printOut = printOut)
    {
        printOut = _printOut;

        return printOut;
    }

    public NoYesId parmDeleteTransId(NoYesId _delete = deleteInventTransId)
    {
        deleteInventTransId = _delete;

        return deleteInventTransId;
    }

    public FileUploadTemporaryStorageResult parmgetFile(FileUploadTemporaryStorageResult _file = fileVal)
    {
        fileVal = _file;

        return fileVal;
    }

    public void run()
    {
        #define.filename("LotID.csv")
        AsciiStreamIo                                   file;
        Array                                           fileLines;
        FileUploadTemporaryStorageResult                fileUpload;
        PurchTable purchTable;
        PurchLine purchLine;
        InventTransOrigin inventTransOrigin;
        InventTrans inventTrans;
        boolean printDoc = false;

        CommaStreamIo io = CommaStreamIo::constructForWrite();
        const str filename = #filename;
        fileUpload = fileVal;

        if (this.parmPrintOut() && !this.parmDeleteTransId())
        {
            io.writeExp(["@AccountsPayable:PurchaseOrderId", "@SYS75853"]);

while select PurchId from purchTable
                where purchTable.PurchStatus == PurchStatus::Received
             
                where purchLine.PurchId == purchTable.PurchId
            {
                io.writeExp([purchLine.PurchId, purchLine.ItemId]);
            }

            // get stream
            System.IO.Stream stream = io.getStream();
            stream.Position = 0;

            // read stream
            System.IO.StreamReader reader = new  System.IO.StreamReader(Stream);
            str csvFileContent = reader.ReadToEnd();

            //send file to user for save
            File::SendStringAsFileToUser(csvFileContent,filename);
        }

        if (fileUpload != null)
        {
            file = AsciiStreamIo::constructForRead(fileUpload.openResult());
            if (file)
            {
                if (file.status())
                {
                    throw error("@SYS52680");
                }
                file.inFieldDelimiter(',');
                file.inRecordDelimiter('\r\n');
            }

            container record;
            io.writeExp(["@AccountsPayable:PurchaseOrderId", "@SYS75853"]);

            if (this.parmPrintOut() || this.parmDeleteTransId())
            {
                while (!file.status())
                {
                    record = file.read();
                    if (conLen(record))
                    {
                        inventTransOrigin = InventTransOrigin::findByInventTransId(conPeek(record,1));

                        if (inventTransOrigin.RecId)
                        {
                            if (this.parmPrintOut() && this.parmDeleteTransId())
                            {
                                printDoc = true;
                                io.writeExp([inventTransOrigin.InventTransId, inventTransOrigin.ItemId]);
                            }

                        }
                    }
                }
                if (printDoc)
                {
                    // get stream
                    System.IO.Stream stream = io.getStream();
                    stream.Position = 0;

                    // read stream
                    System.IO.StreamReader reader = new  System.IO.StreamReader(Stream);
                    str csvFileContent = reader.ReadToEnd();

                    //send file to user for save
                    File::SendStringAsFileToUser(csvFileContent,filename);
                }
            }
        }
    }

    public static void main(Args _args)
    {
        const str controlName = 'ItemFile';
        Dialog dialog = new Dialog("PurchaseOrderCorrection");
        DialogGroup dialogGroup;
        DialogField dialogPrintOut;
        DialogField dialogDelete;
        FormBuildControl            formBuildControl;
        ReadAndExportData postingIssue = new ReadAndExportData();

        dialogGroup = dialog.addGroup("PurchaseOrderCorrection");
        dialogGroup.columns(2);

        dialogPrintOut = dialog.addField(extendedTypeStr(NoYesId));
        dialogPrintOut.label("@SYS12608");

        dialogDelete   = dialog.addField(extendedTypeStr(NoYesId));
        dialogDelete.label("DeleteCorruptedPO");

        formBuildControl = dialog.formBuildDesign().control(dialogGroup.name());

        FileUploadBuild  dialogFileUpload = formBuildControl.addControlEx(classstr(FileUpload), controlName);
        dialogFileUpload.baseFileUploadStrategyClassName(classstr(FileUploadTemporaryStorageStrategy));
        dialogFileUpload.fileNameLabel("@SYS308842");

        if (dialog.run())
        {
            FileUpload fileUploadControl = dialog.formRun().control(dialog.formRun().controlId(controlName));
            FileUploadTemporaryStorageResult fileUploadResult = fileUploadControl.getFileUploadResult() as FileUploadTemporaryStorageResult;

            postingIssue.parmPrintOut(dialogPrintOut.value());
            postingIssue.parmDeleteTransId(dialogDelete.value());
            postingIssue.parmgetFile(fileUploadResult);
            postingIssue.run();
        }
    }

}

Get label value in other than the default language

Hi,

In dynamics365 for operations, you can see labels by default of en-us, when you use the tool "find labels" under Dynamics AX tab.

TO see labels in other languages

public static void main(Args _args)
{
    info(SysLabel::labelId2String(literalstr('@SYS1'), 'en-gb'));
}

Happy Daxing :)