Monday, February 16, 2015

Passing parameters to another form and open it in Edit mode

Below code can be used to pass one parameter from one form to another and open that form in Edit mode.

Args            args;
str             defaultFormOnTable;
MenuFunction    menuFunction;

args = new Args();
args.record(CustTable::find(‘test account’));

menuFunction = new MenuFunction(menuitemDisplayStr(CustTable), MenuItemType::Display);

if(menuFunction)
{       
   menuFunction.openMode(OpenMode::Edit);
   formRun = menuFunction.create(args);
   if(formRun)       
      formRun.run();     
}

In this example I opened customers form in Edit mode by passing customer account 'test account'as a parameter.

How to validate Email and URL through X++

With default functionality in AX, Email address and URL can be of any format and these do not get validated as per their respective correct formats.

Existing functionality

Accounts receivable | Common/Customers | All customers | Customer form | Under Contact information fast tab



Someone can put Email address in any format as I did "faisal" which is not a correct format of email address. Same applies for URL under contact information for customers.

Customized functionality

I created a new class with two static methods to validate these attributes as follows by taking concept from this blog post

/// <summary>
///    Class to validate Logistics Electronic Address using Regex
/// </summary>
class LogiscticsElectronicAddressValidator
{
} 
/// <summary>
///    This method accepts a EMail and validates this using REGEX
/// </summary>
/// <returns>
///    true or false based on Regex match
/// </returns>
Static Server boolean validateEMail(EMail    _eMail)
{
    Boolean   xppBool;
    System.Boolean netBool;
    Str MatchEmailPattern =
       @"^(([\w-]+\.)+[\w-]+|([a-zA-Z]{1}|[\w-]{2,}))@"
     + @"((([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\.([0-1]?
       [0-9]{1,2}|25[0-5]|2[0-4][0-9])\."
     + @"([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\.([0-1]?
       [0-9]{1,2}|25[0-5]|2[0-4][0-9])){1}|"     
     + @"([\w-]+\.)+[a-zA-Z]{2,4})$";
    System.Text.RegularExpressions.Match myMatch;
    ;

    new InteropPermission(InteropKind::ClrInterop).assert();
    myMatch = System.Text.RegularExpressions.Regex::Match(_eMail,MatchEmailPattern);
    netBool = myMatch.get_Success();
    xppBool = netBool;
    CodeAccessPermission::revertAssert();
    Return xppBool;
} 
/// <summary>
///    This method accepts a URL and validates this using REGEX
/// </summary>
/// <returns>
///    true or false based on Regex match
/// </returns>
Static Server boolean validateURL(URL    _url)
{
    Boolean   xppBool;
    System.Boolean netBool;
    Str matchURLPattern = "^(https?://)"
        + "?(([0-9a-z_!~*'().&=+$%-]+: )?[0-9a-z_!~*'().&=+$%-]+@)?" //user@
        + @"(([0-9]{1,3}\.){3}[0-9]{1,3}" // IP- 199.194.52.184
        + "|" // allows either IP or domain
        + @"([0-9a-z_!~*'()-]+\.)*" // tertiary domain(s)- www.
        + @"([0-9a-z][0-9a-z-]{0,61})?[0-9a-z]\." // second level domain
        + "[a-z]{2,6})" // first level domain- .com or .museum
        + "(:[0-9]{1,4})?" // port number- :80
        + "((/?)|" // a slash isn't required if there is no file name
        + "(/[0-9a-z_!~*'().;?:@&=+$,%#-]+)+/?)$";
    System.Text.RegularExpressions.Match myMatch;
    new InteropPermission(InteropKind::ClrInterop).assert();
    myMatch = System.Text.RegularExpressions.Regex::Match(_url,matchURLPattern);
    netBool = myMatch.get_Success();
    xppBool = netBool;
    CodeAccessPermission::revertAssert();
    Return xppBool;

}

To call these methods you need to override two methods (ModifiedField and ValidateField) in LogisticsElectronicAddress table.





After implementing this solution you will get error on entering invalid email and URL addresses.


Sunday, February 15, 2015

Random number generation through X++

AX has buit-in functionality to generate random numbers. You can use Random class (a kernel class, not visible in AOT) for this purpose. There are two more ways to generate random number in X++ One is using RandomGenerate Class which extends Random class and generates values within specified range; Second is using xGlobal::randomPositiveInt32() method.

Example using Random class to generate random numbers (All in CAPITAL letters)

public str generateRandomCode()
{
    str         pass='';
    int         length, counter, randInt,randAscii;
    ;
    length = 4;

    for(counter = 1; counter <= length; counter++)
    {
        randInt = Random.nextInt();
        randAscii = randInt mod 91;

        if((randAscii >= 48 && randAscii <= 57) || (randAscii >= 65 && randAscii <= 90))
        {
            pass += num2char(randAscii);
            continue;
        }
        else
        {
            randAscii = randAscii mod 26 ;
            randAscii += 65 ;
            pass += num2char(randAscii);
            continue;
        }
    }
    return pass;
}

Thursday, February 12, 2015

Exchange rate cannot be found for exchange rate type default between currenies USD & NZD

I came across this error while making some international payments in AX using EFT (method of payment).

"Exchange rate cannot be found for exchange rate type default between currenies USD & NZD"

Resolution:

Go to General Ledger | Setup | Currency | Currency exchange rates
Add new exchange rates for required currencies with start date



Simple :)

Wednesday, February 11, 2015

Firewall settings for Microsoft Dynamics AX components [AX 2012 R2]

If you use Windows Firewall to help protect your computers, Microsoft Dynamics AX components require the settings in the following table. For more information about Windows Firewall, see the Windows documentation.

Document is available to download.






Tuesday, February 10, 2015

Configure Visual Studio to connect/open with correct AOS

Visual Studio is essential to create/edit SSRS reports with MS Dynamics AX 2012 and later releases. Here are steps to configure visual studio with correct AOS (in my case it is development AOS).

  1. Connect with computer where visual studio is installed
  2. Go to location where visual studio file is installed and placed. In my case it is placed at C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE
  3. Right click and sent to create shortcut to desktop (one can create shortcut anywhere)
  4. Right click Visual Studio shortcut (will name something "devenv - shortcut") and take properties
  5. Set target = "C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\devenv.exe" /AxConfig C:\FaisalFareedWorkfolder\DynamicsAXTestSystem.axc

Path of the original visual studio installation file as mentioned in step 2
"C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\devenv.exe"

Path of the configuration file where MS Dynamics AX 2012 configuration is stored. This can be UNC file path or local path, depends on your requirements.
/AxConfig C:\FaisalFareedWorkfolder\DynamicsAXTestSystem.axc

Double click on







Make sure visual studio is connected with correct AOS. This "DynamicsAX_Test" is the configuration name in configuration file used as target in visual studio shortcut's properties.




Running AX 2012: "An invalid directory structure for Microsoft Dynamics AX was detected"

I came across an issue recently when I tried to run Dynamics AX 2012 from client configuration file on 32-bit operating system. Client configuration file was created on 64-bit operating system and was copied to 32-bit operating system computer to use.


As error says it tries to bind directory at path C:\Program Files (x86)\Microsoft Dynamics AX\60\\Client\Bin which was not exist on 32-bit operating system.

Resolution 1

Open client configuration (.axc) file in notepad and change the path at the very end of file. This path should match your directory structure in computer.

Source computer (64 bit) configuration will look like this.

64-bit operating system generated configuration file
Destination computer (32 bit) configuration should look like this. This is the correct path as per 32 bit computer directory structure.


Save configuration file after correcting the paths. It will work smoothly.

Resolution 2

http://blogs.msdn.com/b/emeadaxsupport/archive/2011/03/31/running-ax-2009-client-raises-error-quot-an-invalid-directory-structure-for-microsoft-dynamics-ax-was-detected-quot.aspx?CommentPosted=true#commentmessage

MS Dynamics AX configuration files register in registry when you import/create new configuration files on Dynamics AX configuration. You can also change bindir, datadir and directory paths from registry too, for this you can find registry keys under Computer | HKEY_CURRENT_USER | Software | Microsoft | Dynamics | 6.0 | Configuration | <Configuration name>



Saturday, February 7, 2015

The target prinipal name is incorrect - SSRS with AX

Following error made me worried when I was not able to run (existing or customized) SSRS reports from AX. Reports were working fine few days back and there wasn’t a single change done neither at report server nor with AOS service accounts.




























After digging into issue, came across the issue was services and services groups in AOT. My AOS was connected with TFS and when I got latest from TFS it affects SRSFramework and SSASFramework services and there was some sort of reference lost in service groups.

Resolution:

Generate FULL CIL
Confirm the Business proxy account and AOS service account is same
Register SRSFrameworkService and SSASFrwameworkService services from AOT



Deploy BIServices and UserSessionServices groups from AOT


Restart SQL reporting services


How to enable new Microsoft teams - Public Preview!

New Microsoft Teams is just AWESOME, quick but useful post below shows how you have this preview feature to make your life EASY!  Open Micr...