Financial dimension lookup #MSDyn365FO

Hi Folks! Unfortunately, the useful function SysLookup::lookupDimension() was removed from Dynamics 365 for finance and operations

http://blog.daxteam.net/2015/04/dimenson-value-lookup-by-code-dynamics.html

Now you can find below the alternative to build a lookup based on a financial Dimension, using event handlers on dyn365fo:

    [FormControlEventHandler(formControlStr(SalesLineBackOrder, BusinessLineFilter), FormControlEventType::Lookup)]
    public static void BusinessLineFilter_OnLookup(FormControl sender, FormControlEventArgs e)
    {
        SysTableLookup                      sysTableLookup;
        Query                               query;
        QueryBuildDataSource                qbdsDimensionFinancialTag;
        QueryBuildRange                     qbrFinancialTagCategory;
        #define.BusinessLine('BusinessLine')

        query = new Query();
        qbdsDimensionFinancialTag = query.addDataSource(tableNum(DimensionFinancialTag));
        qbrFinancialTagCategory = qbdsDimensionFinancialTag.addRange(fieldNum(DimensionFinancialTag, FinancialTagCategory));
        qbrFinancialTagCategory.value(strFmt('%1', DimensionAttribute::findByName(#BusinessLine, false).financialTagCategory()));

        sysTableLookup = sysTableLookup::newParameters(tableNum(DimensionFinancialTag), sender);
        sysTableLookup.addLookupfield(fieldNum(DimensionFinancialTag, Value), true);
        sysTableLookup.addLookupfield(fieldNum(DimensionFinancialTag, Description));
        sysTableLookup.addSelectionField(fieldNum(DimensionFinancialTag, FinancialTagCategory));
        sysTableLookup.parmQuery(query);

        sysTableLookup.performFormLookup();
    }

How to send an e-mail in AX 7 using x++

I know that is a well known subject when we’re speaking about x++ but it’s always helpful for new developers or when somebody is in a hurry and needs a quick answer.

In the previous versions of AX we had the SysMailer class for send e-mails trough x++ using just two lines of code.

Probably you already know about the several changes that happened for the developer’s point of view in AX7 and this simple task was one of these, but do not worry because it’s still very simple, see the code bellow as an example:

public static void main(Args _args)
{
    SysMailerMessageBuilder mailer  = new SysMailerMessageBuilder();;
    SysMailerSMTP           smtp    = new SysMailerSMTP();
    try
    {
        mailer.setSubject("AX7 - Sending e-mail through x++");
        mailer.setFrom("axforce@axforce.com");
        mailer.setBody("Axforce.wordpress.com");
        mailer.addTo("mchiovitti@axforce.com");
        mailer.addAttachmentFromFile(@"\\10.1.6.249\xml\test.pdf");

        smtp.sendNonInteractive(mailer.getMessage());
    }
    catch(Exception::CLRError)
    {
        error(CLRInterop::getLastException().toString());
    }
}

Silly code but I’m sure that will be helpful for someone.

See you guys next time. 🙂

Database synchronization trick for AX 7

Probably all of you already know that the AX7 has the Visual Studio as its new IDE, what’s certainly a big change for us.

In this post I’ll explain what are the tools available to perform a sync database and at the end I’ll show you one trick that I’ve learned.

1 – Synchronize on project build

In the project properties you can select this option to perform a database sync after each time that you build your project. I highly recommend you to choose this option when you’re working with Tables/Views/Data Entity because it will only sync the objects that belong within your project.

ProjectDBSync

2 – Synchronize on package build

There are several options to check if you’re performing a package build and one of them is the synchronize database option.

The idea here is to perform a database sync only for the objects that belong to the package that is being built, but this is not what really happens. I’ve tried to build a smaller package with some few tables and it did a full database sync instead. 

FullBuildDBSync

Please let me know if one of you had a different result than mine.

3 – Full Synchronize

If you need to perform a full database sync you can do it at the following path:

FullDBSync

4 – Enable legacy log

In this AX7 current version there is a known issue that makes harder to get the synchronization errors. When an error happens, the application doesn’t tell you what is the cause and neither the object with error.

To be able to trace the synchronization errors you have to enable the legacy log setting straight in the VS settings file that is located in the following path:

C:\Users\Administrator\Documents\Visual Studio 2015\Settings\DynamicsDevConfig.xml

Setting:

FallBackToNative

I hope that Microsoft will fix this issue in the next product release, but in the meanwhile we can use this workaround as an alternative.

Original article here.

See you guys next time ! 🙂

Extension VS Customization in AX 7

So what’s the difference between extensions and customizations in AX and which of them should you choose for your solution?

Model is an unit of development or customization. Extensions get isolated in their assemblies.

Basically, AX 7 introduces a new way of customizing an application by using extensions.

Using extensions allows you to create new model elements and to extend existing model elements. On the other hand, to use customizations you need to create event handlers and new plug-ins.

Some advantages of extensions

  1. You need to manage only your extension artifacts.
  2. You can service your solutions independently without concerns about other customizations.

Original article in ax7dev blog.

What’s new in X++ for AX 7

In this article we describe the main changes in the X++ language for AX 7. Almost all changes will appear because of the Visual Studio’s IDE.

No more p-code

  1. In AX 7 the new X++ compiler generates CIL only.
  2. Compiled X++ code now runs exclusively as .NET CIL.
  3. CIL runs much faster.

Enhancements to X++

  1. try … catch … finally:a564c-picture1
  2.  

  3. Initialize stuff in the class declaration statement.d3203-picture2
  4.  

  5. Declare variables in smaller scopes, not just at the start of methods.
  6. VAR keyword is available as a shortcut that allows the compiler to infer the type of the declared variable.
  7. An attribute declaration can omit suffix of attribute name if suffix is “Attribute”.

Backward-incompatible changes to X++

  1. No longer part of the X++ language (compile error) – changeSite, pause, window 
  2. The keywords client and server will be ignored, because all compiled X++ code is executed as .NET CIL on the server.
  3. CIL helper methods have been removed.
  4. AX 7 eliminates the concept of AOT > Jobs. Instead use static main method of a class and then set the class as the startup object from the AX 7 project.
  5. Use const type instead macros.

AX7 LINQ Provider for use in C#

Language Integrated Query (LINQ) is a set of classes and methods that enable you to access data that is stored in a variety of places and formats.

When very few records are fetched C# LINQ is three times longer than while select.

Original article in AX7DEV Blog.

Moving temporary data from Ax 2012 to SSRS

I would like to talk a little bit about the SRSTmpTblMarshaller class.

For those who doesn’t know yet, this class makes it possible to share existing temporary data between an AX object and the SSRS.

There are several ways in which you could use a temporary table with the SRSS, but let’s consider the following scenario:

Your report will be printed through a form button and that form uses a temporary table as DataSource. This data can also be manipulated by the user, so you cannot reprocess this data with the DataProvider class.

Instead of turning the temporary table in a regular table – I’ve saw some people doing that, you can use the SRSTmpTblMarshaller as a way batter alternative:

  1. In your contract class, you need to create an accessor method do keep this recordId from the SrsTmpDataStore or you can simply extend the SrsTmpTblMarshallerContract that already have this.
  2. In your controller class, you need to call the sendTmpTblToDataProvid method using your table buffer as parameter. This will store your table buffer as a container inside the SrsTmpDataStore table and return the recordId:
    protected void preRunModifyContract()
    {
        SrsTmpTblMarshallerContract contract = this.parmReportContract(    ).parmRdpContract() as SrsTmpTblMarshallerContract;
    
        // get the Temp table, and marshall it across to SSRS
        new SRSReportRunPermission().assert();
        contract.parmTmpTableDataRecId(SRSTmpTblMarshaller::SendTmpTblT    oDataProvider(bankReconciliationPrintoutTmp));
    }
    
  3. Request permission by using the assert method in the  SRSReportRunPermission class.
  4. Set the recordId inside the accessor method that you’ve created.
  5. Then in your data provider class you can unpack your table buffer using the method getTmpTbl from SRSTmpTblMarshaller class using as parameters the recordId from the SrsTmpDataStore table that you kept in your contract:
    private void initBankReconciliationPrintoutTmp()
    {
        SrsTmpTblMarshallerContract contract = this.parmDataContract()     as  SrsTmpTblMarshallerContract;
    
        //Temp Table Object that was returned from SRSDataCarrier
        new SRSReportRunPermission().assert();
        bankReconciliationPrintoutTmp = SRSTmpTblMarshaller::getTmpTbl(    con tract.parmTmpTableDataRecId());
    
        SRSTmpTblMarshaller::deleteTmpTblData(contract.parmTmpTableData    Rec Id());
        CodeAccessPermission::revertAssert();
    }
    
  6. Remove your buffer from the scope using the deleteTmpTblData method.

You can also check the BankReconcilliation report. It’s a good example on how to use this functionality. 🙂

Dynamics AX 7 Development – Packages, Models, Projects

Packages, Models and Projects in AX 7. Let’s figure out what do they stand for.

  • Package in AX 7 is an independent deployable unit of one or more models.
  • Model is a group of elements (metadata and source files) that typically constitute a distributable software solution.
  • Project is a simple Visual Studio project that stores AOT elements. The project helps you group the elements.

A simple way to understand is described on the following image:

Package folders are located in the model store folder of the AX 7 application. The default model store folder is “c:\packages”.

Model folders are contained in their package folder. A model folder contains type-specific folders.

Every dependency of packages are described in descriptor files and can be shown in AX 7 viewer.

In model view, AE is organized by models. The package that a model belongs to is shown in parenthesis next to the model name.

The main purpose of the VS project is to store AOT elements. AX 7 has not Shared or Private projects. Each user has their own projects that each of them related only to one model. Use multiple projects in Visual Studio solution to work with elements from different models.

So that’s the way how Packages, Models and Projects interact with each other.

Original article in ax7dev blog.