Blog

Name is Anant Dubey and the intent to create this blog is to discuss the problems and issues that developer face in the dynamics AX development and to share the new things that come up with the new version of AX.

Friday, February 27, 2015

Get Vendor Id based on Vender's Name in ax 2012

static void VendorId(Args _args)
{
    VendTable       VendTableloc;
    DirPartyTable   DirPartyTableloc;
    str a;

    select DirPartyTableloc join VendTableloc where DirPartyTableloc.Name == "Test" && VendTableloc.Party == DirPartyTableloc.RecId;

    a = VendTableloc.AccountNum;

   info(strfmt("%1",a));
}

How to track item's address in ax 2012

static void S3_TrackItemsAddress(Args _args)
{
    VendTable               vendTable;
    str                     description, address, city;
    InventTable             inventTable;
    DirPartyTable           DirPartyTableloc;
    ;

select inventTable where inventTable.ItemId == salesline.ItemId;
        select DirPartyTableloc
        join vendTable where DirPartyTableloc.Name == inventTable.PrimaryVendorId &&
             vendTable.Party == DirPartyTableloc.RecId;

        vendTable   = VendTable::find(vendTable.AccountNum);
        description = DirParty::primaryPostalAddress(vendTable.Party).displayLocationDescription();
     
        address     = DirParty::primaryPostalAddress(vendTable.Party).Address;

        city        = DirParty::primaryPostalAddress(vendTable.Party).City;

    info(strFmt("%1,%2, %3", description,city, address));
}

Thursday, January 1, 2015

Importing a General Journal using Data Import/Export Framework in AX 2012 R3

Importing a General Journal using Data Import/Export Framework in AX 2012 R3
Here is a tutorial on how to configure Dynamics AX 2012 to import a general journal from a CSV file. The steps below are using Contoso demo data.

  1. Create a new folder on the root of the C: Drive and name it “DIEF”:
  2. Navigate to Data import export framework | Setup | Data import export framework parameters. Click “Browse” next to “Shared working directory” and select the “DIEF” folder we created. Once selected, click “Validate”.
  3. Close the “Data import export framework parameters” form.
  4. Go to Data import export framework | Setup | Source data formats. Enter “GLJOURNAL” for the “Source name” and “Type” = “File. In the parameters on the right side, enter “File format” = “Delimited”, “First row header” = TRUE, “Row delimiter” = “{CR}{LF}”, “Column delimiter” = “Comma {,}”, “Text Qualifier” = “*”, and “Role separator” = “;”. Click “Application”, and then select “CostCenter”, “Department”, and “ExpensePurpose”. Enter “CostCenter-Department-ExpensePurpose” for the “Dimension format” value.

  5. Go to Data import export framework | Setup | Target entities. Click “New” and enter “Entity type” = “Entity”, “Entity” = “Custom”, “Entity name” = “GLJOURNAL”, “Staging table” = “DMFLedgerJournalEntity”, “Entity class” = “DMFLedgerBalanceEntityClass”, and “Target entity” = “DMFLedgerJournalTransEntity”. Close the “Target entites” form.
  6. Go to Data import export framework | Common | Processing group. Type “GLJOURNAL” for the “Group name”, Ctrl+S to save, and click “Entities”. 
  7. On the “Select entities for processing group” form, enter “GLJOURNAL” for both the “Entity name” and the “Source data format”. Click “Generate source file”.
  8. On the “Wizard” form, click “Next”. For the “Display data” fields, select the following and put them in the following sequence: JournalName, JournalNum, LineNum, CurrencyCode, TransDate, Voucher, AccountType, LedgerDimension, AmountCurDebit, AmountCurCredit, OffsetAccountType, OffsetLedgerDimension. Click “Generate sample file”.
  9. A .txt file should open, and save it to the root of the C: drive.
  10. Click “Finish” on the “Wizard” form. Close the “Select entities for processing group” form. Close the “Processing group” form.
  11. Go to General ledger | Setup | General ledger parameters. Click “Number sequences”. Right-click “Gene_10” next to “Journal batch number” and click “View details”.
  12. Click “Edit”, copy the format. To copy click the “General” fast tab and note the “Next” value, in my case format is “INMF-00441”.

  13. Close the “Number sequences” form and the “General ledger parameters” form.
  14. Navigate to General ledger | Setup | Journals | Journal names. Select “GenJn” and right-click the “Acco_18” next to “Voucher series”, and then click “View details”.
  15. On the “Number sequences” form, click “Edit”. copy the number sequence format as copied earlier. In my case format is, “VN00000038”.
  16. Close all forms.
  17. Open Excel. Click File | Open. Navigate to the C: drive and select the “GLJOURNAL.txt” file (You may need to change the drop menu to “All Files (*.*)”)
  18. On the “Text Import Wizard” form, click “Delimited” and click “Next”. Check the box for “Comma” and click “Finish”.
  19. In line 2, enter the following values for each header:
  1. JournalName = GenJn
  2. JournalNum = INMF-00441(Value from step 12)
  3. LineNum = 1
  4. CurrencyCode = USD
  5. TransDate = 01/01/2015
  6. Voucher = VN00000038 (Value from step 16)
  7. AccountType = Ledger
  8. LedgerDimension = 110180-OU_1-OU_3566-Training "Or" 110110-022-001
  9. AmountCurDebit = 10
  10. OffsetAccountType = Ledger
  11. OffsetLedgerDimension = 110101-OU_1-OU_3566-Training "Or" 110120-022-001
  • Click File | Save As. Click “CSV (Comma delimited)” for the “Save as type” drop-menu.
  • Close Excel.
  • Go to Data import export framework | Common | Processing group. Select the line for “GLJOURNAL” and click “Entities”.
  • Click the folder icon next to “Sample file path”, and select the .csv file from step 20. Click “Generate source mapping”. Close the infolog.
  • Close the “Select entities for processing group” form.
  • On the “Processing group” form, select the line for “GLJOURNAL” and click “Get staging data”.
  • A form for “Create a job ID for the staging data job” should open and populate with a “Job ID”. Click “OK”.
  • On the “Staging data execution” form, click “Preview”. Verify the columns are correct, and then click “Run”.
  • Close the infolog.
  • On the “Processing group” form, click “Copy data to target”. Select the “Job ID” created earlier, and click “OK”. On the “Target data execution” form, click “Run”, then click “OK”.
  • Close the Infolog.
  • Go to General ledger | Journals | General journal. Locate the imported journal, and click “Lines”.
  • Notice the values imported properly, and click Post | Post. The journal posts successfully.
reference: https://community.dynamics.com/ax/b/axsupport/archive/2014/07/17/importing-a-general-journal-using-data-import-export-framework-ax-2012.aspx

Friday, December 19, 2014

How to get DateNull in in ax 2012

One of my co new bie developer with the Dot net background had really hard time in figuring out the dateNull in x++ due to two reasons
  1. X++ does not have intellisense like Dot net which could help the newbie like my colleague
  2. The null value in  x++ debugger is shown as “Zero (0)”. So lots of new bie take the null value for date time as 0 and go in wrong direction
So i just thought to do a simple post on it. I know for a senior or the developer at mid level may find this simple and irrelevant to be posted at the blog, however i think this may help the new developer who are at the edge of starting new career in x++.
So here it goes
DateNull for the date can be checked by two ways
  1. Global::DateNull()
  2. or like this
    if (endDate != mkdate(1,1,1900)
The minimum value for the date in x++ is 1/1/1900 and max value is 12/31/2154
If you have utcDateTime here is how you can set dateNull and maximum value
todayDate = DateTimeUtil::minValue();
maximumDate =  DateTimeUtil::maxValue();
blankUtcDate = utcDateTimeNull();
reference:: https://dynamicsaxposed.wordpress.com/2010/07/06/how-to-get-datenull-in-axapta-x/

Some Useful date functions in AX 2012

There are a lot of functions in dynamics Ax for dates. Followings are some date time functions I used extensively.
Some times we need to get month, year form date we can get these with the use of following functions in Dynamics ax
int _Months;
int _Years;
//Get day from date
_DayOfMonth =dayOfMth(systemdateget());;
// Get month from date
_Months = dayOfMth(systemdateget());
//Get month from date
//mthOfYr(systemdateget())
//Get year from date
_Years =year(systemdateget());
Mkdate.
This functions help you create date from input values.  For example if you have input for month and year, and want to create date for first of selected month of selected year, you can create it as.

Date _CustomDate;
Date _LastDateOf Month;
Int month_number;
Int years_numbers;
Int day_number;
;
Day_number=1;
Month_number=4 ; // say April
Years_Number=2012;
_customDate =mkdate(Day_number, Month_number, Years_Number);

Info _customDate;
 Endmth;

This method returns the last date of month what ever the date we given to it. for example if we give the above created  date then it will return the last date of april
_LastDateOfMonth = endmth(_customDate);

Usually we need loop through next month, next year , nextQtr,prevQtr, pervious month, pervious year.
 We are use them as

Date _nextDate;

_NextDate = nextMth(today);
_NextDate=prevMth(today);
_NextDate=nextYr(today);
_NextDate =preYr(today);
_NextDate=prevQtr(today);
_NextDate=nextQtr(today);
 Usually we have to convert date to UTCDateTime. That is usally case when we have to query on createdatetime filed of very table, which filled when new row is created.
We for this purpose we have to create use DateTimeUtil::newDateTime function. This function takes two values one for date, and second for time. So time values will be range beween 0 and 86400. It means when value time is 00:00:00 value will be 0 and when time is 23:59:59 then value will be 86400. Consider following code which creates start and end date for same date.

Date _Currentdate;
utcDateTime _UtcStartPeriod;
utcDateTime _UtcEndPeriod;
 ;
 _currentdate=today();

_UtcCurrentPeriod =  DateTimeUtil::newDateTime(_currentdate,0);
_UtcEndPeriod = DateTimeUtil::newDateTime(_UtcEndPeriod,86400);
reference::https://community.dynamics.com/ax/b/alirazatechblog/archive/2012/09/03/some-useful-date-functions-in-dynamics-ax-x.aspx 

Wednesday, September 24, 2014

Using Controller Class in Developing SSRS Reports in Microsoft Dynamics AX 2012

Using Controller Class in Developing SSRS Reports in Microsoft Dynamics AX 2012



Overview

Controller class is used to control the report execution as well as preprocessing of the report data. The SSRS reporting framework uses this class to modify the report dialogs, calling the SQL Server reporting services, as well preprocessing parameters for the report.
Following are the scenarios where Controller class can be used:
  1. Modifying a report query based on the input data
  2. Modifying report contract data based on the input data
  3. Control a report parameters dialog
  4. Open different reports/designs from the same menu item based on the input data
  5. Reports that are opened from a form
To create a controller class, extend it with SrsReportRunController.

Prerequisites

  1. Microsoft Dynamics AX 2012
  2. Reporting services extensions must be installed in Dynamics AX

Sample Controller Class

  1. Create a new class. Open AOT → Classes
  2. Right Click on Classes and select New Class. Name it asSSRSDemoController.
example of creating a new class in Dynamics AX
 
  • Open the Class declaration by right clicking on it and selectingView code.
example of viewing code in AOT class AX
 
  • Now write the following code:
class SSRSDemoController extends SrsReportRunController

{

}
  • Create a new method and write the following code:
public static client void main(Args args)

{

//define the new object for controller class

SSRSDemoController ssrsDemoController;

ssrsDemoController = new SSRSDemoController();

//pass the caller args to the controller

ssrsDemoController.parmArgs(args);

//set the report name and report design to run

ssrsDemoController.parmReportName(ssrsReportStr(SSRSSessionQuery,Design));

//execute the report

ssrsDemoController.startOperation();

}

Examples of Controller Class Usage

Based on different scenarios, different methods are overridden as shown in the following examples:
  1. Modifying report query based on the input data

  • Used in those scenarios where a report query needs to be modified based on the caller args parameters or recorded before the report parameter dialog is rendered.
  • Override prePromptModifyContract method to modify the report query as shown below:
public void prePromptModifyContract()
{
    //add a range in the report query  
      SrsReportHelper::addParameterValueRangeToQuery(this.getFirstQuery(),tableNum(SSRSReportDemo),fieldNum(SSRSReportDemo, RecId),SysQuery::value(this.parmArgs().record().RecId));
}
Note: prePromptModifyContract is called by report controller before the parameter dialog is shown to the User.
  • Modifying report contract data based on the input data

  • Used in those scenarios where report contract parameters need to be modified based on the caller args prior to the execution of the report.
  • Override preRunModifyContract method to modify the report contract as shown below:
protected void preRunModifyContract()
{    
    //define object for report contract
    SSRSDemoContract contract;

    //get the reference of the current contract object
    contract = this.parmReportContract().parmRdpContract() as SSRSDemoContract;

    //modify the parameter value of the contract
    contract.parmType(this.parmArgs().parm()); 
}
Note: preRunModifyContract is called by report controller before the report is run.
  • Control report parameters dialog

  • In some scenarios, a report parameter dialog should not be visible to the end user. Controller class is also used to control the visibility of the report parameter UI.
  • Add the following code in the main method of the controller class before startOperation method call to hide/show the report parameter UI:
//hide the report parameter dialog
ssrsDemoController.parmShowDialog(false);
  • Open different reports from the same menu item based on the input data

  • It is used in those scenarios where different reports or different designs of a same report need to be opened from a same menu item depending upon the caller args.
  • Write the following code in main method to achieve this scenario:
public static client void main(Args args)
{    
    //define the new object for controller class
    SSRSDemoController ssrsDemoController;
   
    ssrsDemoController = new SSRSDemoController();
    
    //pass the caller args to the controller
    ssrsDemoController.parmArgs(args);
        
    //if report is run from edit mode then run the EditDesign of the report otherwise run the NewDesign of the report
    if(args.parmEnum() == FormOpenMode::ForEdit)
    {
        //set the report name and report design to run
        ssrsDemoController.parmReportName(ssrsReportStr(SSRSSessionQuery,EditDesign));    
    }
    else
    {
        //set the report name and report design to run
        ssrsDemoController.parmReportName(ssrsReportStr(SSRSSessionQuery,NewDesign));    
    }   
    
    //execute the report
    ssrsDemoController.startOperation();   
}
  • Reports that are opened from a form

  • Controller class is also used when reports are opened from a form and are needed to show selected record details.
  • Use either prePromptModifyContract method or preRunModifyContract method to achieve this scenario.

Tuesday, August 5, 2014

Shortcut Keys in AX

Button Description:- Debugging
--------------------------------

Stop Debugging (Shift +F5) Enables the Watch window.

Insert/Remove Breakpoint:-(F9) Inserts or clears a breakpoint.

Enable/DisableBreakpoint:-(Ctrl + F9) Enables or disables a breakpoint.

Remove all breakpoints:-(Ctrl + Shift + F9) Clears all breakpoints.

Step Over:-(F10)Steps to the next line of code in the current function/method.

Step Into (F11) Steps into the current line if it contains a function or method call.

Step Out (Shift + F11) Steps out of the current function or method.

Run to Pointer (Ctrl + F8) Continues execution until reaching the location of the pointer in the source window.


------------------------------------------------------------------------------------------------------

Button Description:-
--------------------

New (Ctrl+ N) Creates a new job.

Save :- Saves the changes to the active method.

Go (F5):- Executes the class, form, or project.

Toggle Breakpoint (F9):- Turns breakpoints on and off.

Enable/Disable Breakpoint (Ctrl + F9):- Enables or disables a breakpoint.

Remove all breakpoints (Ctrl + Shift + F9):- Deletes all breakpoints from the method.

Compile (F7) :-Checks the code for errors, compiles the code,and saves it.

Lookup properties/methods (Ctrl + Space):- Helps you locate methods or properties.

Lookup label/text (Ctrl +Alt + Space):- Helps you find a label.

Run an Editor Script (Alt + M):- Helps you choose between a selection of scripts.

Help (F1):- Accesses X++ code editor window help.

(shift-F4):-check functions in code window .