Wednesday, June 15, 2016

Using XE Currency Restful API in AX - Using Basic Authentication method

static void XECurrencyConverionRestfulAPI(Args _args)
    System.Net.HttpWebRequest           webReq;
    System.Net.HttpWebResponse          webRes;
    CLRObject                           clrObj;
    System.IO.Stream                    stream;
    System.IO.StreamReader              streamRead;
    System.IO.StreamWriter              streamWrite;
    System.Net.ServicePoint             servicePt;
    System.Net.WebHeaderCollection      headers = new System.Net.WebHeaderCollection();
    str                                 userNamePassword, userNamePassword64, ret;
    System.Byte[]                       byte;
    System.Text.Encoding                encoding = System.Text.Encoding::get_UTF8();
    //This line gives the user control to run unmanaged and managed code
    new InteropPermission(InteropKind::ClrInterop).assert();
    // Create Object for adding headers
    headers = new System.Net.WebHeaderCollection();
    clrObj = System.Net.WebRequest::Create('');
    webReq = clrObj;
    //Set Method Type
    // Set Content type
        userNamePassword = 'YOURUSERNAME:YOURPASSWORD';
        //64 bit encode user name and password
        byte = encoding.GetBytes(userNamePassword);
        userNamePassword64 = System.Convert::ToBase64String(byte);
        headers.Add("Authorization", 'Basic ' + userNamePassword64);
        //Add header to request
        //Gets the response object
        webRes = webReq.GetResponse();
    catch (Exception::CLRError)
        //Access the last CLR Exception
        //See AifUtil::getClrErrorMessage for another alternative
        //how to parse the Exception object
    //Get Stream
    stream = webRes.GetResponseStream();
    streamRead = new System.IO.StreamReader(stream);
    ret = streamRead.ReadToEnd();

Tuesday, March 15, 2016

Unable to cast object of type 'Dynamics.Ax.Application.DictField' to type 'Dynamics.Ax.Application.SysDictField

I found some standard Microsoft code in AX which was working fine in x++ however, when the code executed in IL (Aif Interface), it would throw an error

"Unable to cast object of type 'Dynamics.Ax.Application.DictField' to type 'Dynamics.Ax.Application.SysDictField"

I found that the variable was declared as SysDictField but the object was instantiated as new DictField() - this works fine in x++ but would fail in IL based on OOP principles. 

The solution was to change the following line of code from new dictField(...) to new sysDictField(...)

SysDictField        dictField;

dictField   = new dictField(_variable.RefTableId,_variable.RefFieldId);

should be:

dictField   = new SysDictField(_variable.RefTableId,_variable.RefFieldId);

Wednesday, December 16, 2015

No matching MessageFilter was found for the given Message

We are calling an AIF web service from a .Net API. Everything was working and suddenly after a model store deployment, we were unable to use that service and were getting following error.

No matching MessageFilter was found for the given Message

I tried everything and could not find anything wrong. Web.config, WCF bindings everything was OK but still it would not work.

After spending couple of hours, I removed the Service References (not just update, remoed and re-added) from my code, rebuilt the API and published on IIS again and it started working.

Sunday, December 6, 2015

Sales order confirmation in batch - adding extended logic

The out of the box Sales order confirmation functionality allows us to either confirm Sales order using a click of a button (on Sales order form/list page) or we can schedule the confirmation of Sales order using a batch job (it also supports late selection query). This all works fine. However, if you want to perform additional tasks on each Sales order once it is confirmed, you will need to write some code. The class structure is something like that


Any developer familiar to inheritance would go and override the run method of SalesFormLetter_Confirmation class to perform the additional updates after the super call and it will work perfect when a Sales order is confirmed using a button. However, it will NOT work as expected when runs under a batch. It is because, batch creates multi threaded tasks and leaves them to execute later. The code written in run method of SalesFormLetter_Confirmation class would run before the Sales order is actually confirmed (under different thread) and you will not achieve your desired results as code would not be execute for SOs being confirmed under a batch.

To overcome this issue, the code must be executed when the thread actually confirms the Sales order. After performing some debugging using Visual Studio and analysing the threads I found few ways to achieve the desired results and execute the custom code for each and every Sales order under the batch right after it gets Confirmed.

  1. There is a class called "FormLetterServiceBatchTaskManager". It has run method - write your code there after the base class' run gets executed. Better check the this.ParmDocumentStatus to execute your code only for the document type you are working on. (if this.ParmDocumentStatus() == DocumentStatus::Confirmation)
  2. Write your code in method after journal gets created (Again, check the document status and execute your code only for your desired document type). 
There are some other classes which actually creates journal and they could also be considered for performing similar tasks based on your requirements.
  1. FormLetterJournalCreate (Parent class - following are few of its child classes)
  2. SalesConfirmJournalCreate
  3. SalesPickingListJournalCreate etc.

Dynamics AX Load Balancing tips

Working with Single AOS environment and Load balanced environment is very different. Specially, when it comes to releasing code in production environment or making changes in AIF service data policies. Following are few things which I learnt in my recent project:

  1. If running multiple AOSs for load balancing and you need to make data policy changes (i-e need to enable or disable fields in a web service), you must bring all AOSs down and restart the service when change is made and CIL is performed.
  2. If running multiple AOSs and made some code change that needs CIL change. Again, must bring all AOSs down and restart them when change is made to make the change effective in all environments (servers)
  3. If running multiple AOSs and modified workflow (i-e a new workflow version is added), Must refresh cache in all other environments. You don't need to bring production environment down for that purpose and just login to all servers and refresh the cache (Tools > Cache > Refresh AOD, data, dictionary)
  4. If you are using load balancing and you have written custom .net API which calls AIF services. The custom .Net API MUST be deployed on physical cluster and not the load balanced one. Otherwise, it won't be able to authenticate and you will get NTLM authentication error.

I will keep updating this post as I find and learn more. 

Tuesday, October 27, 2015

Start Visual Studio in CUS, VAR layer

If you are developing for EP and creating/modifying web controls. You would notice that changes you make in Visual Studio will be published in USR layer. To start visual studio in some other layer, create a Visual Studio shortcut > Right Click > Properties and set target to something like this:

"C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\devenv.exe" /AxConfig  "C:\AXCU8_DEV10_VAR.axc"

The highlighted text is basically pointing to the AX configuration file for VAR, CUS layer.

Saturday, August 15, 2015

AX 7 - New Features

Recently, I came across a white paper providing summary of new features that have been implemented in AX7.  The paper needed partner source access so I am providing highlights here for those who don't have access to partner source. Please note that the White paper is draft and subject to change.

What can you do?
AX 2012
‘AX 7’
Access the client, anytime, anywhere
The AX 2012 desktop client provided a full set of forms, but was limited to running on Windows machines and required installation. Terminal Server was often used with the desktop client to enable access over a WAN. The Enterprise Portal web client provided a reduced set of forms.
The two AX 2012 clients have been replaced by a single, standards based web client that provides the full set of functionality of the desktop client with the reach of the Enterprise Portal client.

What can you do?
AX 2012
‘AX 7’
Export account structures to Excel

Not supported
You can now select an account structure and export that to Excel.
View ledgers and advanced rule structures associated with an account structure on a single form
In AX 2012, the user has to navigate to multiple forms to see the ledger that the account structure is using.
Fact boxes have been added to the account structure form.
Filter Management Reporter (labeled Financial reporting in ‘AX 7’) reports based on dimension, attributes, dates, and scenarios
All filtering of Management Reporter reports was handled through the design of the report. If a user with viewing privileges wanted to view a report for a different date, for example, this required a report designer to make the modification
Report options have been added so when viewing a report, different filters can be applied and a new report is generated based on those filters.
View Management Reporter (financial reports) within the ‘AX 7’ client
A separate web client was used for viewing Management Reporter reports.
A list of all financial reports can be accessed within the ‘AX 7’ client. The user selects a report to view, and the report is rendered within the ‘AX 7’ client.
Monitor budget vs actuals and create ledger forecasts using the Ledger budgets and forecasts workspace and additional inquiry forms
Not available
The workspace can be accessed through the ‘AX 7’ dashboard. It includes links to a number of new inquiry forms: Actuals vs budget summary, Budget control statistic summary, Budget register entries, Budget plans.
Create layouts for budget plans and forecasts
The Budget plan document is viewed as a list of lines with effective dates and amounts for financial dimension combinations. The user must create and use Excel templates to view budget plan data in a pivot.
An unlimited number of layouts is available for budget plans and forecasts. You can combine selected financial dimensions, user defined columns, and other row attributes (such as comments, projects, assets, etc.) in the layout. Users can switch the layout for the budget plan document on the fly and edit data using any selected layout. Budget planning configuration is simplified by eliminating scenario constraints and using layouts to define which data can be viewed and edited in each budget plan document stage.
Print the Vendor Invoice Transactions report with information from the Detailed Due Day List which includes the days past due.
In AX 2012, you had to print two different reports: the “Detailed Due Day List” and the “Vendor Invoice Transactions” report.
The information contained on the two reports were consolidated onto the “Vendor Invoice Transactions” report. The Detailed Due Day List was deprecated.

What can you do?
AX 2012
‘AX 7’
Transfer skills and certificates to class participants upon course completion
Manual process in AX 2012.
Upon completion of a course a new option will be available to update participant’s records with the new skills and certificates.
Quick employment verification capability
Manual process in AX 2012
Accessed from a workspace or the employee form HR can quickly verify employment.
Enable employees to view, update, and delete information from the system
Available in AX 2012 with limited view and update capability.
This feature is enabled for employees and contractors to view a wide range of personal data with optional workflow when creating new, updating existing, or deleting information from the system.
Enable managers to view or edit employee information
Available in AX 2012 with limited view and update capability.
Managers are empowered based on configuration settings and security to view or edit employee information.
Encrypt ID numbers
Not Available
All Employee ID (SSN) numbers are encrypted.
Access compensation processing results
Available only at time of processing
Compensation processing results can now be accessed at any point after the process has run.
Access benefit processing results
Available only at time of processing
Benefits processing results can now be accessed at any point after the process has run.
View Date Effective timeline changes
Not Available
This comparison tool is available for Employees, Positions, and Jobs. It provides a comprehensive view of changes from one version of a record to another.
View employees by company
Manual process in AX 2012 through filtering
Employee and Contractor lists are automatically filtered by the company you’re logged into.
Update course participants list
Not Available
Course participants can be removed from the participants list.
Manage compensation events in mass
Not Available
This feature provides a streamlined processing of compensation changes for employees.