Wednesday 29 October 2014

Display customized Text In Status Bar- Axapta 2012

Here i'm sharing the code to Display customized Text In Status Bar

//Copy and paste the below code in a Job

static void statusbar(Args _args)
{
    str customtext;
    ;

    customtext = "Test";

    // Force the text to be shown
    xUserInfo::statusLine_CustomText(true);
    infolog.writeCustomStatlineItem(customtext);

}



@ Rahul Talasila

Tuesday 28 October 2014

Filtering Records in a Form - Microsoft Dynamics Axapta

Hello Guys...


In this post i'm sharing steps how to do the Filtration of records in a Form

Here  i'm filtering records based on the selected gender(m/f)

Step 1 :

Go to Form-> Methods->class declaration and declare QueryBuildRange.

public class FormRun extends ObjectRun
{
    QueryBuildRange range;
}

Step 2:
Go to Data sources->your datasource->Add a Range in init() method of the DataSource.

public void init()
{
    super();
    range = this.query().dataSourceName("Test_Filteration").addRange(fieldNum(Test_Filteration,Gender));
}
//Note : You can use dataSourceNo also

Step 3 :

Go to Data sources->your datasource->Override the executeQuery() method


public void executeQuery()
{
    range.value(Gender.valueStr());
    super();
}

//Note : Enable "Gender"Auto-declaration to "Yes" in design

Step 4 :

Finally  Call the executeQuery() method in the Selection Changed method of the ComboBox(Gender).


public int selectionChange()
{
    int ret;

    ret = super();
    Test_Filteration_ds.executeQuery();
    return ret;
}




@ Rahul Talasila

Monday 27 October 2014

Import Vendor Balances In Microsoft Dynamics Axapta 2012

Here I'm sharing code to import Vendor Opening Balances Lines.

Note : The below code import only Lines.


-> Copy and paste below code in AOT->Jobs(Compile Job before using)
->open excel and fill the data according to the below format and save in CSV format
->Run job and browse file and press ok

Csv Format :

column1 - Journal Number
column2 - MainAccountNum
column3 - Dimension1
column4 - Dimension2
column5 - Dimension3
column6 - Debit Amount
column7 - Credit Amount
column8 - Transaction Date
Column9 - Description
Column10 - InvoiceId
Column11 - PostingProfile

//Code Starts From Here- @ Rahul Talasila

static void VendorOpeningBalances(Args _args)
{
    CommaIO                   csvFile;
    container                 readCon;
    counter                   icount,inserted;
    Dialog                    dialog;
    DialogField               dfFileName;
    FileName                  fileName;
    LedgerJournalACType       ledgerJournalACType;
    AxLedgerJournalTable      axLedgerJournalTable ;
    AxLedgerJournalTrans      axLedgerJournalTrans;
    container                 accPatternvend,accPatternledger;
    container                 offSetPattern;
     DimensionDynamicAccount   ledgerdimension;
   str transdate;
    ;
     inserted =0;
    #File
    dialog     = new Dialog("Pick the file");
   // dialog
    dfFileName = dialog.addField(extendedTypeStr(FileNameOpen));
    dialog.filenameLookupFilter(["All files", #AllFiles]);
    if(dialog.run())
    {
       filename =  dfFileName.value();
    }
       csvFile  =  new CommaIO(filename,'r');

    if(csvFile)
    {
        ttsBegin;
        while (csvFile.status() == IO_Status::OK)
        {
          readCon  = csvFile.read();
          if(readCon)
            {
                transdate = conPeek(readCon, 8);
                axLedgerJournalTable = new AxLedgerJournalTable();
                axLedgerJournalTrans = new AxLedgerJournalTrans();
                axLedgerJournalTrans.parmJournalNum(conPeek(readCon, 1));
                axLedgerJournalTrans.parmTransDate(str2Date(transdate,123));
                axLedgerJournalTrans.parmAccountType(LedgerJournalACType::Vend);
                ledgerdimension = DimensionStorage::getDynamicAccount(conPeek(readCon, 2), LedgerJournalACType::Vend);
                axLedgerJournalTrans.parmLedgerDimension(ledgerdimension);
                axLedgerJournalTrans.parmDefaultDimension(LedgerJournalTable::find(conPeek(readCon, 1)).DefaultDimension);
                axLedgerJournalTrans.parmAmountCurDebit(conPeek(readCon, 6));
                accPatternledger = [conPeek(readCon,2) + conPeek(readCon,3) + conPeek(readCon,4) + conPeek(readCon,5), conPeek(readCon,2),conPeek(readCon,3),conPeek(readCon,4),conPeek(readCon,5)];
                axLedgerJournalTrans.parmOffsetAccountType(LedgerJournalACType::Ledger);
                axLedgerJournalTrans.parmOffsetLedgerDimension(AxdDimensionUtil::getLedgerAccountId(accPatternledger));
                axLedgerJournalTrans.parmAmountCurCredit(conPeek(readCon, 7));
                axLedgerJournalTrans.parmTxt(conPeek(readCon,9));
                axLedgerJournalTrans.parmInvoice(conPeek(readCon,10));
                axLedgerJournalTrans.parmPostingProfile(conPeek(readCon,11));
                axLedgerJournalTrans.save();
                icount++;
                inserted++;
            }
        }
      ttsCommit;
    }
   info(strfmt("%1 records Inserted out of %2",inserted,icount));

}


Note : Based on ledger account dimension structure your account pattern will change

@ Rahul Talasila

Sunday 26 October 2014

"Unable to preview the report, install the Business Intelligence Development Studio feature of Microsoft SQL Server. For more information, see http://go.microsoft.com/fwlink/?LinkId=212331”



Solution:
-> Axapta 2012 needs to integrate with Visual Studio 2010.
-> Therefore you have to install BIDS (Business Intelligence Development Studio). 
->You can use a SQL Server 2008 R2 installation image to install it (it’s one of the components you can select during installation of “A new standalone server or additional components” on the client machine.




After the installation open report in visual studio - 2010. 

 Rahul Talasila

Thursday 23 October 2014

Ternary Operator (?) In Axapta 2012

Ternary Operator (?)  is one of code optimization technique in axapta .It acts as a IF condition in axapta


Syntax : 

expression1 ? expression2 : expression3
expression1 must be a Boolean expression. If expression1 is true, the whole ternary statement resolves to expression2; otherwise it resolves to expression3.
expression2 and expression3 must be of the same type as each other.
Example :
By using Ternary operator(?):
int nVar = 2;
;
print nVar < 3 ? nVar + 1 : nVar - 1; // print output 3.
pause;
Same Code By using If() Condition:
int nVar = 2;
;
if(nVar < 3)
{
  nVar = nVar +1;
}
else
{
nvar = nvar-1;
}
// print output 3.

How To Delete Usage Data in Microsoft Dynamics Axapta 2012

Here i'm sharing steps to reset usage data in axapta 2012


-> Open the Microsoft Dynamics AX client.
-> Click File > Tools > Options.
-> Click Usage data.
-> On the General tab, click Reset.


@Rahul Talasila

How To Refresh The Application Object Directory (AOD) Cache

Here I'm sharing steps to refresh the Application Object Directory (AOD) cache.


This will clear cached application object information for all items in the application object tree (AOT) of Microsoft Dynamics AX.


-> Open the Microsoft Dynamics AX client.
-> Open the development workspace.
-> Click Tools > Caches > Refresh elements.

After the cache has been cleared, the Infolog displays a message indicating that AOD elements have been refreshed.



@ Rahul Talasila

Error while setting server report parameters. Error message: The item '/DynamicsAX/*********************' cannot be found. (rsItemNotFound)

Some time we get the below error while opening reports in axapta.

Reason : Reports are not deployed

Solution : To deploy reports.

Here i'm sharing steps how to deploy reports in axapta 2012


 Open Windows PowerShell as an administrator by following these steps:

-> Click Start > Administrative Tools.
-> Right-click the Microsoft Dynamics AX 2012 Management Shell option.
-> Click Run as administrator.


-> paste below command and press enter .Takes 10-25 minutes to deploy reports.

Deploy All Reports :

Publish-AXReport –ReportName *


Deploy a Specific Report :

Publish-AXReport -ReportName Vend


@ Rahul Talasila

Tuesday 21 October 2014

Import General Ledger Opening Balances In Axapta 2012

Here I'm sharing code to import GL Opening Balances Lines.

Note : The below code import only Lines.


-> Copy and paste below code in AOT->Jobs(Compile Job before using)
->open excel and fill the data according to the below format and save in CSV format
->Run job and browse file and press ok

Csv Format :

column1 - GL Journal Number
column2 - MainAccountNum
column3 - Dimension1
column4 - Dimension2
column5 - Dimension3
column6 - Debit Amount
column7 - Credit Amount
column8 - Transaction Date
Column9 - Description


//Code Starts From Here- @ Rahul Talasila

static void GL_OpeningBalances(Args _args)
{
    CommaIO                   csvFile;
    container                 readCon, accPattern,offSetPattern, dimPattern1;
    counter                   icount,inserted;
    Dialog                    dialog;
    DialogField               dfFileName;
    FileName                  fileName;
    AxLedgerJournalTable      axLedgerJournalTable ;
    AxLedgerJournalTrans      axLedgerJournalTrans;
    MainAccount               mainAccount;
    MainAccountNum            mainAccountNum;
    DimensionDynamicAccount   ledgerdimension;
    str transdate;
    ;
     inserted =0;
    #File
    dialog     = new Dialog("Pick the file");
   // dialog
    dfFileName = dialog.addField(extendedTypeStr(FileNameOpen));
    dialog.filenameLookupFilter(["All files", #AllFiles]);
    if(dialog.run())
    {
       filename =  dfFileName.value();
    }
       csvFile  =  new CommaIO(filename,'r');

    if(csvFile)
    {
        ttsBegin;
        while (csvFile.status() == IO_Status::OK)
        {
          readCon  = csvFile.read();
          if(readCon)
            {
                MainAccountNum = conPeek(readCon,2);
                mainAccount = mainAccount::findByMainAccountId(MainAccountNum);

                if(!mainAccount)
                {
                    info(strFmt("%1",MainAccountNum));
                }
                transdate = conPeek(readCon, 8);
                axLedgerJournalTable = new AxLedgerJournalTable();
                axLedgerJournalTrans = new AxLedgerJournalTrans();
                axLedgerJournalTrans.parmJournalNum(conPeek(readCon, 1));
                axLedgerJournalTrans.parmTransDate(str2Date(transdate,123));
                axLedgerJournalTrans.parmAccountType(LedgerJournalACType::Ledger);
                accPattern = [conPeek(readCon,2) + conPeek(readCon,3) + conPeek(readCon,4) + conPeek(readCon,5), conPeek(readCon,2),conPeek(readCon,3),conPeek(readCon,4),conPeek(readCon,5)];
                axLedgerJournalTrans.parmLedgerDimension(AxdDimensionUtil::getLedgerAccountId(accPattern));
                axLedgerJournalTrans.parmDefaultDimension(LedgerJournalTable::find(conPeek(readCon, 1)).DefaultDimension);
                axLedgerJournalTrans.parmOffsetAccountType(LedgerJournalACType::Ledger);
                axLedgerJournalTrans.parmAmountCurDebit(conPeek(readCon, 6));
                axLedgerJournalTrans.parmAmountCurCredit(conPeek(readCon, 7));
                axLedgerJournalTrans.parmTxt(conPeek(readCon,9));
                axLedgerJournalTrans.save();
                icount++;
                inserted++;
            }
        }
         ttsCommit;
    }
  info(strfmt("%1 records Inserted out of %2",inserted,icount));
}


Note : Based on ledger account dimension structure your account pattern will change

@ Rahul Talasila

Axapta Application Compilation In CU7

In cu7 we can compile the application by using the below comamnd

-> Go AOS installed server 
-> Open command prompt(cmd) as a administrator

->paste the below code(Before pasting change aos name ,aos number, workers)

->Press Enter .

cd \Program Files\Microsoft Dynamics AX\60\Server\<YOUR AOS NAME>\bin
axbuild.exe xppcompileall /aos=01 /altbin="C:\Program Files (x86)\Microsoft Dynamics AX\60\Client\Bin" /workers=4

NOTE : <your AOS NAME> -    C:\Program Files\Microsoft Dynamics AX\60\Server (Here you can see you AOS name)

(aos = 01) - check your Axapta Server configuration and give the aos number


You should stop the AOS service before you start

@ Rahul Talasila

Fatal SQL condition during login. Error message: "The internal time zone version number stored in the database is higher than the version supported by the kernel (5/2). Use a newer Microsoft Dynamics AX kernel."

Some times AOS  will not start and shows the below error in the Event Viewer.

Fatal SQL condition during login. Error message: "The internal time zone version number stored in the database is higher than the version supported by the kernel (5/2). Use a newer Microsoft Dynamics AX kernel."


Reasons :
->  when you restore axapta database.
-> when you install more than one AOS in the same server
-> when running more than two axapta environments in the same server

Solution :

->Open  Sql Management Studio

->Go to MicrosoftDynamicsAx(Axapta Database) database and dbo.SQLSystemVariables table and edit records. In that go to SYSTIMEZONESVERSION  record and update value (5/2) in the place of 5 to 2.



@Rahul Talasila

How to Install Management Reporter in Ax 2012 R3 - Step by step


Here I'm sharing steps how to install Management Reporter in Ax 2012 R3

Sql Server Version : 2014
Windows server : 2012 R2
Axapta : Ax 2012 R3

 Management Reporter 2012 CU10 (version 2.1.10001.112)

Download Link https://mbs.microsoft.com/customersource/northamerica/MR/downloads/service-packs/MROverview
customer/partner id and password is required 

Note : If you are using sql 2012 then install MR from Ax 2012 R3 set up.

Steps 

Run MR Setup


Insall->Management Reporter Server

Give service account user id and password 
Database Server : DB server name
Select windows authentication(If want to use"sa" then uncheck it and give "sa" and password)

Give password and confirm password

Port Num : 4712(By default this the port number . If you want you can change but remember the port number because while installing MR client we use the same port number)

Services Endpoint Port: 8201 (Generally people confuse here 8101 or 8201.  8101 is WSDL port number not service endpoint port)
AOS Server: AOS Installed Machine Name
User Name : AOS execution user name and password
DataBase Server : DB server Name

DataBase Name : MicrosoftDynamicsAX(Axapta DB Name)


Click Next

After few minutes Management Reporter will be installed.

Then open configuration console and you will have a new node under ERP Integration. Select the node and ENABLE INTEGRATION and click on refresh.

Again go back to the setup and click on

Install->Management Reporter Client->Next->Next

Server : http://servername:4712
(serverName : MR installed server Name)
click next and finish the installation.





@Rahul Talasila

Integrate Google Maps In Axapta 2012 R2 & Axapta 2012 R3


In Axapta system we can see customer / vendor address in bing.com maps.

In this customization I will show the same in google maps.




Before:

Accounts receivable/Common/Customers/All customers

Select any customer and edit

In Address tab we can see “Map”. When we click on that we can see customer address in bing maps.

After

Go to AOT-> Classes -> smmutility ->mapit (Method)

Copy and replace the below code in mapit method

/// <summary>
/// Opens Bing maps with the address.
/// </summary>
/// <param name="_address">
/// The address to map.
/// </param>
public static void mapIt(LogisticsPostalAddress _address)
{
   // #DEFINE.MapURL('http://maps.bing.com/default.aspx?where1=\%1')//Commented By Rahul
    #DEFINE.MapURL('https://www.google.com/maps/place/')//N-Code Added By Rahul Talasila
    #DEFINE.comma(',')
    #DEFINE.newLine('\n')

    str     address;
    ;
    if (_address)
    {
        address = _address.Street + #comma +
                  _address.City + #comma +
                  _address.State + #comma +
                  _address.ZipCode + #comma +
                  _address.CountryRegionId;

        // Replace the newline with comma
        address = strReplace(address, #newline, #comma);
        // URL encode
        address = System.Web.HttpUtility::UrlEncode(address);
        // Add the address to the URL
        infolog.urlLookup(strFmt(#MapURL+ address));//N-Code Changed By Rahul Talasila
    }
}


Go back to the customer->address and click on map.


 Below link helped me ..
http://querystring.org/google-maps-query-string-parameters/

@Rahul Talasila



Thursday 16 October 2014

Example : DialogButton with box YesNo


Dialogbutton db;
;
db = box::yesNo("Choose Yes or No", dialogButton::Yes, "YesNo Box Example");
if (db == dialogButton::Yes)
  {
      info( "We chose Yes");
  }
else if (db == dialogButton::No)
{
     info( "We chose No");
}

@RahulTalasila

How to resolve unbalanced TTSBegin/TTSCommit Error in Axapta


static void resetTTS(Args _args)
{
   while (appl.ttsLevel() > 0)
   ttsAbort;
}

using cacheAddMethod in display and edit methods


Display and edit methods are used on forms to display data that must be derived or calculated based
on other information in the underlying table. These methods can be written on either the table or the
form. By default, these methods are calculated one by one, and if there is a need to go to the server
when one of these methods runs, as there usually is, each function goes to the server individually. The fields associated with these methods are recalculated every time a refresh is triggered on the form, which can occur when a user edits fields, clicks menu items, or presses F5. Such a technique is expensive in both round trips and the number of calls placed to the database from the Application ObjectServer (AOS).

Caching cannot be performed for display and edit methods that are declared on the data source
for a form because the methods require access to the form metadata. If possible, you should move
these methods to the table. For display and edit methods that are declared on a table, use the
FormDataSource.cacheAddMethod method to enable caching.Caching cannot be performed for display and edit methods that are declared on the data source for a form because the methods require access to the form metadata. If possible, you should move these methods to the table. For display and edit methods that are declared on a table, use the FormDataSource.cacheAddMethod method to enable caching. This method allows the form’s engine to calculate all the necessary fields in one round trip to the server and then cache the results. To use cacheAddMethod, in the init method of a data source that uses display or edit methods, call cacheAddMethod on that data source and pass in the method string for the display or edit method.For example, look at the SalesLine data source of the SalesTable form. In the init method, you will

Example

public void init()
{
super();
salesLine_ds.cacheAddMethod(tableMethodStr(SalesLine, invoicedInTotal), false);
salesLine_ds.cacheAddMethod(tableMethodStr(SalesLine, deliveredInTotal), false);
salesLine_ds.cacheAddMethod(tableMethodStr(SalesLine, itemName), false);
salesLine_ds.cacheAddMethod(tableMethodStr(SalesLine, timeZoneSite), true);
}

Tuesday 14 October 2014

How To Refresh elements in the AOT


If several developers modify elements simultaneously in the same installation of AX 2012, each
developer’s local elements might not be synchronized with the latest version. To ensure that the local
versions of remotely changed elements are updated, an auto refresh thread runs in the background.
This auto refresh functionality eventually updates all changes, but you might want to force the refresh
of an element explicitly. You do this by right-clicking the element, and then clicking Restore. This
action refreshes both the on-disk and the in-memory versions of the element.


Typically, the general integrity of what’s shown in the AOT is managed automatically, but some
operations, such as restoring the application database or re installing the application, can lead to
inconsistencies that require manual resolution to ensure that the latest elements are used. To perform
manual resolution, follow these steps:


1. Close the AX 2012 client to clear any in-memory elements.
2. Stop the Microsoft Dynamics Server service on the Application Object Server (AOS) to clear
any in-memory elements.
3. Delete the application element cache files (*.auc) from the Local Application Data folder
(located in %LocalAppData%) to remove the on-disk elements.

         C:\Users\youruserid\AppData\Local

Note : Make sure show hidden files,folders,and drivers option enabled

@Rahul Talasila

All Element Names In The AOT use The Following Structure



 <Business area name> + <Functional area> + <Functionality, action performed, or type of content>


Prefixes are commonly used to indicate the team responsible for an element.
For example, in the name BankLCImport the prefix Bank is an abbreviation
of the business area name (Bank), LC describes the functional area (Letter Of Credit),
and Import lists the action performed (import).

@Rahul Talasila

New Element Naming Conventions In Ax 2012



When creating new elements in the AOT, ensure that you follow the recommended naming conventions.


Prefix
Description
Ax
Microsoft Dynamics AX typed data source
Axd
Microsoft Dynamics AX business document
Asset
Asset management
BOM
Bill of material
COS
Cost accounting
Cust
Customer
Dir
Directory, global address book
EcoRes
Economic resources
HRM/HCM
Human resources
Invent
Inventory management
JMG
Shop floor control
KM
Knowledge management
Ledger
General ledger
PBA
Product builder
Prod
Production
Proj
Project
Purch
Purchase
Req
Requirements
Sales
Sales
SMA
Service management
SMM
Sales and marketing management, also called customer relationship management (CRM)
Sys
Application frameworks and development tools
Tax
Tax engine
Vend
Vendor
Web
Web framework
WMS
Warehouse management

@Rahul Talasila

Adding a newline into a string in C# and X++

Below is the sample code we can use for  adding a newline after every occurrence of "@" symbol in the string in C#   using System...