Friday, 31 August 2012

AX2009 Server migration from one machine to another

Server migration of AX2009 is easier if you do it through SQL Backup/Restore. Following are the steps:
  1. Go to the SQL server of the database from the where you need to take the backup.
  2. Backup the full database.
  3. Go the the SQL server of the database on which you need to restore the database.
  4. Restore the full database.
  5. Copy the Appl folder from  C:\Program Files\Microsoft Dynamics AX\50\Application
  6. In server configuration you need to point to this application path as shown above.
Now you need to change the server name at the database level from SQL as shown below:

Select * from dbo.BATCHSERVERGROUP
--Update BATCHSERVERGROUP set SERVERID = '01@NewAOS' where SERVERID = '02@OldAOS'

Select * from BATCHSERVERCONFIG
--Update BATCHSERVERCONFIG set SERVERID = '01@NewAOS' where SERVERID = '02@OldAOS'


Select * from SYSCLUSTERCONFIG
--Update SYSSERVERCONFIG set SERVERID = '01@NewAOS' where SERVERID = '02@OldAOS'

Select * from SYSSERVERSESSIONS
--Delete dbo.SYSSERVERSESSIONS
Select * from BATCH
--Update BATCH set SERVERID =  '01@NewAOS' where SERVERID = '02@OldAOS'

Select * from SYSCLIENTSESSIONS
--delete SYSCLIENTSESSIONS

Hope this helps.

Cannot select a record in Customer parameters (CustParameters). An unsupported NULL value has been selected from the database."

Recently our customer came up with one of the issues,  the issue was that some of the users where not able to access the Sales order and Customer master data. They use to get this message:



"Cannot select a record in Customer parameters (CustParameters). An unsupported NULL value has been selected from the database."

The reason was usage data, there was something wrong with their usage data. I tried to clear the usage data and close AX and open again, issue was resolved.

Steps to clear usage data:
  1. Open AX
  2. Go to Tools
  3. Select Option
  4. Click "Usage Data"
  5. In th General tab click "Reset" (Note that all the user changes will be gone after reset).


Thursday, 24 May 2012

How to merge and get vendor master/ customer master address using X++ code in AX 2012

In AX 2012 there is method formatAddress in LogisticsPostalAddress table. This method will merge all the details of the address. In my case I was updating the vendor address so I created a job as shown below:


//Something like this:

logisticsPostalAddress.Address = logisticsPostalAddress::formatAddress(logisticsPostalAddress.Street,
                    logisticsPostalAddress.ZipCode,
                    '',
                    logisticsPostalAddress.CountryRegionId,
                    '',
                    '');
logisticsPostalAddress.update();

How to reduce/flush the TempDB size in AX2012

In AX 2012 all the temp data is stored in TempDB database, which normally occupies alot of space after certain days. Below is the path for TempDB:

<YourDrive>:\SQL\MSSQL10_50.MSSQLSERVER\MSSQL\TempDB






You might see on the above path that there is a a database which is of a big size in GB's. You simply need to restart SQL Server service or restart the machine. This will flush all the temp memory from this database.

Hope this helps!

Invalid file name message.

This is the error message you normally get when you use the the wrong file convention, As in the example below I used "\" instead of "\\" in the file path, as AX only excepts "\\":

static void ReadingFile(Args _args)
{
    TextIo      inputFile;
    //This syntax is for reading file in a local machine, we always use "\\" instead of "\"
    // AX does not read "\"
    inputFile = new TextIo("C:\test.txt", 'R');
    if (inputFile)
    {
        info("File found");
    }
}






















Solution:

static void ReadingFile(Args _args)
{
    TextIo      inputFile;
    //This syntax is for reading file in a local machine, we always use "\\" instead of "\"
    // AX does not read "\"
    inputFile = new TextIo("C:\\test.txt", 'R');
    if (inputFile)
    {
        info("File found");
    }
}

This is the correct way. Same goes for network path, you need to use "\\\\" instead of "\\", as shown below:

static void ReadingNetworkFile(Args _args)
{
    TextIo      inputFile;
    //This syntax is for reading file in a local machine, we always use "\\" instead of "\"
    // AX does not read "\"
    inputFile = new TextIo("\\\\AXServer\\test.txt", 'R');
    if (inputFile)
    {
        info("File found");
    }
}








Stack trace: Invalid attempt to call WinAPI::findFirstFile running in CIL on the client.

Stack trace: Invalid attempt to call WinAPI::findFirstFile running in CIL on the client

This error you will normally encounter when running a batch job. The issue is that batch processing doesn't suppport WINAPI::findFirstFile method. Actually I was trying to find a file in the folder and moving to some other folder, you can use this alternative:

public void run()
{
System.IO.DirectoryInfo di;
System.Type arrayType;
System.Array array;
System.IO.FileInfo fi;
FilePath filePath, moveFilePath, shortFile;
int i;
int l;

;

super();

    baseFolder = tEC_InterfaceSetup.TEC_DefaultFolder +"\\";
    di = new System.IO.DirectoryInfo(baseFolder);
    arrayType = System.Type::GetType("System.IO.FileInfo");
    array = System.Array::CreateInstance(arrayType, 1);
    array = di.GetFiles("*" + #txt);
    l = array.get_Length();


    if (l > 0)
    {
        //Find the files in the base folder and iterate.
        for (i = 0; i < l; i++)
        {
            fi = array.GetValue(i);
            mainFolder = fi.get_FullName();
            foundBaseFileName = fi.get_Name();  
         //**********Your logic************
        }
        
        InterfaceTransfer::moveFile(foundBaseFileName , moveFilePath);
    }
}



server static void moveFile(str fileName, str newFileName)
{
    #File
    Set                 permissionSet;
    permissionSet =  new Set(Types::Class);
    permissionSet.add(new FileIOPermission(fileName,#io_write));
    permissionSet.add(new InteropPermission(InteropKind::ClrInterop));
    CodeAccessPermission::assertMultiple(permissionSet);
    System.IO.File::Move(fileName, newFileName);
    CodeAccessPermission::revertAssert();
}


Hope this helps.


   

System.IO.IOException: The process cannot access the file because it is being used by another process.

If you encounter this error that mean that you are trying to access a file which is not closed at the moment. The file your trying to access is still open, below is the screen-shot:




















Solution:

The solution is that you simple need to close the file the TextIO class. For closing the file you neeed to use this syntax:

TextIo inputFile;
;

inputFile.finalize();

// This will close the file and then you can proceed with your remianing operation on the file.

Access denied to Bank account number(AccountNum) in table Print checks (TmpChequePrinout)

If you encounter an error "Access denied to Bank account number(AccountNum) in table Print checks (TmpChequePrinout)" when generating computerized cheque as shown below:





Solution:

Assign the AP Payment Clerk role to that user who is trying to generate the CPU cheque, this will resolve your problem.

Wednesday, 23 May 2012

How to set minimum/empty, maximum date for date control in AX.

This job will explain how to set different operations on date conrol in AX using Global class:

static void GlobalClass(Args _args)
{
    Date    newDate;
    ;

    //Normal Dates
    info("Normal Dates:");

    //Get's today's date.
    info(strfmt('%1', today()));

    //Get's minimum/empty date (i.e. 1/1/1900).
    //Tough for this one you are not able to see the output as 1/1/1900, but when you set this to
    //database field you will see 1/1/1900 set in the date control.
    info(strfmt('%1', Global::dateNull()));

    //Get's maximum date (i.e. 12/31/2154).
    info(strfmt('%1', Global::dateMax()));

    //How to add 2 months in date
    newDate = Global::dateMthFwd(today(), 2);
    info(strfmt('%1', newDate));
}

Output:

How to get minimum/empty,maximum date and DateTime in user preferred time zone for utcDateTime control

This job will explain the simple usage of DateTimeUtill class in AX.

static void UtcDateTimeClass(Args _args)
{
    Date    todaysDate;
    ;

    //UTC Date Time
    info("UTC Dates:");

    //Get's today's utc date time.
    info(strfmt('%1', DateTimeUtil::utcNow()));

    //Get's minimum utc date time (i.e. 1/1/1900).
    //Tough for this one you are not able to see the output as 1/1/1900, but when you set this to
    //database field you will see 1/1/1900 set in the date control.
    info(strfmt('%1', DateTimeUtil::minValue()));

    //Get's minimum utc date time (i.e. 1/1/1900).
    info(strfmt('%1', utcDateTimeNull()));

    //Get's maximum utc date time (i.e. 12/31/2154).
    info(strfmt('%1', DateTimeUtil::maxValue()));

    //Convert UtcDateTime to normal date
    todaysDate = DateTimeUtil::date(DateTimeUtil::utcNow());
    info(strfmt('%1',todaysDate));

    //How to get the time in user time zone
    info(strfmt('%1', DateTimeUtil::applyTimeZoneOffset(DateTimeUtil::utcNow(),
        DateTimeUtil::getUserPreferredTimeZone())));
}

Output:

'Like' and 'Not Like' in Dynamics AX query

In X++ you can use 'Like' to get the query result: E.g

static void Job12(Args _args)
{
    CustTable   custTable;
    ;
   
    while select custTable
        where custTable.AccountNum like "11*"
    {
       info(strfmt('%1', custTable.AccountNum));
    }
}

This job will return all the customer account starting from "11", as shown below:























In X++ you can use 'Not Like' to get the query result: E.g

static void Job13(Args _args)
{
    CustTable   custTable;
    ;
   
    while select custTable
        where !(custTable.AccountNum like "11*")
    {
       info(strfmt('%1', custTable.AccountNum));
    }
}

This job will return all the customer account NOT starting from "11", as shown below:

Reports showing username and password when opening SSRS report

When opening a report you see the username and password dialog














Now what is the possible reason for this issue. You might have changed your AX reporting service account to any other account in the reporting service extension recently, as shown below.

















Solution:

The solution for this might take some more time as expected. You need to open internet explorer and Run as Administrator. The type the reporting server link as shown below:

















Now you need to test one report e.g (TaxTable). Click on the Arrow sign and select 'Manage'

















Now browse to the 'Datasource' node of the reprot and check what is the data source applied, your datasource will have this option selected "Credential supplied by the user running the report" as shown below:
















Now by default this should be 'Windows integerated secutiy'. In order to achive this you need to delete all the reports first from the reporting server and then re-deploy all the reports from AX. Once you re-deploy the report from AX you will see all the report changed back to 'Windows integerated secutiy' option and then report will work fine. After re-deploy you window will look like this:
















Now try running the report again. Report will work fine.








Report labels does not show up in X++ report

The report labels do not display, or the report shows label IDs, like Labels!@SYS2123 instead of the label values. 
There are two reason for this type of issue:
   1.  Either you have recently moved your AX service account from AX domain admin group
   2. Or your have changed your SSRS service account password

Solution:
  1. From the Start menu, point to All Programs, click the SQL Server folder, click the Configuration Tools folder, and then click Reporting Services Configuration Manager.  
  2. In Reporting Services Configuration Manager click Connect and then click Service Account.
  3. Set the password and then click Apply. The account and password should be the same as the Microsoft Dynamics AX proxy account. 
  4. System will ask you to backup your encrytion key, and then will some settings on the backhand.
  5. Now Click the ServerName/MSSQLSERVER on the left top of the reporting server and then click Stop. Then click Start to restart the server. Always check with the SQL administrator and make sure no other users are connected to the server before you restart the server.
Now try opening your report again, your issue will be resolved.