Tuesday, November 26, 2013

AX 2012 Get Current Worker Id

Question:
How to get Current Worker Id in Dynamics AX 2012

Answer:
HcmWorkerRecId workerRecId = DirPersonUser::currentWorker();

Thursday, November 21, 2013

Debugging Enterprise Portal code in AX 2009/2012

File open dialog on AX 2012 form

Problem:
I want to show a file open dialog on AX 2012 form but when I click the open dialog button it doesn't respond.

Solution:
On Runbase OR Sys operations framework, all you have to do is set the EDT to FileNameOpen and dialog will appear, however, on AX form only setting the EDT will not do. You will need to add following methods to your form methods node.

str filenameLookupFileName()
{
    return "";
}

FilenameFilter filenameLookupFilter()
{
    return ["@SYS134052", #AllFilesName+#AllFilesExt];
}

str filenameLookupInitialPath()
{
    return "";
}

str filenameLookupTitle()
{
    return "Select a trade agreement to import";
}

Thursday, June 27, 2013

AX 2012 Post Partial Sales Order using x++ code

In Dynamics AX 2012, we often need to post Sales Order using x++ code. It is very easy to post complete sales order using x++ code by utilizing the SalesFormLetter class. However, what if we need to post the sales order partially and not all the lines.

We have a chooseLinesQuery() method available in SalesFormLetter class that accepts a query object to post only the lines you want to post. See example below.

    SalesTable salesTable;
    SalesFormLetter salesFormLetter;
    Query query;
    QueryRun queryRun;
    QueryBuildDataSource qbds;

    query = new Query(QueryStr(SalesUpdatePackingSlip));
    qbds = query.dataSourceTable(tableNum(SalesLine));

    // Build query range to find those lines which needs to be posted.
    qbds.addRange(fieldNum(SalesLine, mzkBillingDate)).value(queryValue(systemDateGet()));
    qbds.addRange(fieldNum(SalesLine, SalesStatus)).value(queryValue(SalesStatus::Backorder));
    queryRun = new queryRun(query);

    salesFormLetter = SalesFormLetter::construct(DocumentStatus::Invoice);
    salesFormLetter.chooseLinesQuery(queryRun);
    salesFormLetter.update(salesTable);


Tuesday, June 18, 2013

AX 2012 AIF cannot set field value from .net application

I was working with one of the AIF document services in Dynamics AX 2012. I was trying to create general journal record from .net application but I noticed that few of my field values were not getting saved in AX. AIF will not throw any error, records were getting created but few fields were missing values even I provided the values.

For example:
ledgerJournalTrans.AmountCurCredit  = Convert.ToInt64(500.00);
           
I was trying to set the Credit value like above but I could not. I then found that we can set the specified attribute for such fields to true and then AIF will consider to set the values for these fields. See example below.

ledgerJournalTrans.AmountCurCreditSpecified = true;

When I added this statement, everything started to work as expected.

Sunday, June 16, 2013

Understanding types of AIF services in AX 2012

Dynamics AX 2012 offers different type of services that can be used to perform several operations. It is very important to understand which type of service should be used to perform your desired operation.

There are 3 types of services that are available in Microsoft Dynamics AX 2012.


  1. Document Services
    • Document services are services which expose a business entity. For example, Customer, Vendor, Employee, Sales Order.
    • You can Map the business entity using Query and run through Document Service Wizard to build the web service and perform CRUD operations.
  2. Custom Services
    • To expose a custom x++ logic. 
    • Say, you have a custom module and you want to expose some logic/code to your custom application.
  3. System Services
    • System services are kind of utility services.
    • Up and running when AOS starts.
    • Can be used for interactive clients 
    • Build Ad-hoc query