Friday, 5 February 2016

Pack() and unpack() methods in Dynamics AX

Pack and unpack is Dynamics language for serialization -- putting object-specific data in a writeable format and later reading it back to create an object in the exact same state.
Most of the interactive objects in Dynamics will automatically check for saved user data when invoked and instantiate accordingly.  Perhaps you remember running a report and the next time you opened the report your previous query and parameter values were already there.  This happens because of pack and unpack.
The majority of what makes pack and unpack confusing is macros, so let's do a simple example not using macros at all.  Let's say we have a class that has two date values I need to persist between runs: startDate and endDate.
So when pack() gets called, I need to store both variables.  (If you don't understand the way containers work, look them up on MSDN first, otherwise this won't make sense).
container pack()
{
return [startDate, endDate];

The framework will take whatever pack returns and store it in user data.  So when the object is instantiated, unpack() gets called in order to reinitialize the values.
boolean unpack(container _packedValues)
{
[startDate, endDate] = _packedValues;
return true;
}

Follow what's happening here?  We expect _packedValues to contain startDate and endDate in that order, so we assign those values to our class variables.
Now let's imagine we want to add another class variable that needs to be stored: isPosted
To do this, we'll have to modify our pack to return
[startDate, endDate, isPosted]
and our unpack to assign all three:
[startDate, endDate, isPosted] = _packedValues;
Hm, but what about values that were stored before our modification?  That container assignment won't work because _packedValues will only contain 2 values (startDate and endDate).  So let's make the first value in our packed data identify the version of the packed data so we can handle old values without crashing.
container pack()
{
return [1, startDate, endDate, isPosted];
boolean unpack(container _packedValues)
{

boolean ret = true;
int version; 

;
if (conpeek(_packedValues) == 1)
{
[version, startDate, endDate, isPosted] = _packedValues;
}
else
{
ret = false;
}
return ret;

Ok, so now if I need to add more variables, I need to change the version number in both pack and unpack, but now old data will make unpack() return false, which will initialize the parameter defaults.
So now let's add some macros so we only have to change one spot when we change what we want to pack.  In our classDeclaration, we'll create 2 macros: one for the version of the data, and one for the values we wish to store.
classDeclaration()
{
#define.CurrentVersion(1)

#localMacro.CurrentList
startDate,
endDate,
isPosted
#endMacro 
If you're unfamiliar with macros, what they do is fill in exactly what the macro says at compile time.  So whenever you write #CurrentVersion, the compiler fills in '1'.  Whenever you write #CurrentList, the compiler fills in 'startDate, endDate, isPosted'.  So now we can change our pack() and unpack() to look like this:
container pack()
{
return [#CurrentVersion, #CurrentList];

boolean unpack(container _packedValues)
{
int version; boolean ret = true;
;
if  (conpeek(_packedValues) == #CurrentVersion)
{ [version, #CurrentList] = _packedValues;
}
else
{
ret = false;

return ret;
}


Note:Copied from https://community.dynamics.com/ax/f/33/p/67248/122709

Tuesday, 5 January 2016

Installation of Hyper-v of AX7


Prerequisite to install AX7 Hyper-V
1.Drive size needed: 150GB
2.RAM: 12GB(16GB recommended
3.OS: windows 8/8.1/10(PRO) or windows server 2012/2012R2
4.Office365 account(atleast trail)

Step 1: Run application, that extracts remaining zips, constitute to 113GB

Step 2: Enable Hyper-v
Search "windows Features" enable Hyper-V.
For Server Click on "Add roles and Features"



Step 3: Search "Hyper-V management"
Create Virtual switch network




Step 4:Create New virtual Machine





RAM size should be allocated min 8GB, So enter 8000MB


Give the location of extracted .VHD location

Step 5:
After successful creation of VM,

Search Hyper-V
Click connect and start
password:pass@word1

Step 6:
click on the below Icon to register

Step 7:
Enter your Office 365 account ID and wait for confirmation dialogue
Step 8:
Enter below link in browser in hyper-V and login with office365 account


Step 9:

For development, need to go visual studio.
Project>new>Microsoft dynamics
In visual studio, View>application explorer you will get AOT.

Happy Daxing... :)

Note: Command to enable Hyper-V in Windows 11 Home single laguage edition
Open Cmd as administartor and run

@echo off pushd "%~dp0"
dir /b %SystemRoot%\servicing\Packages\*Hyper-V*.mum >List.txt
for /f %i in ('findstr /i . List.txt 2^>nul') do dism /online /norestart /add-package:"%SystemRoot%\servicing\Packages\%i"
Dism /online /enable-feature /featurename:Microsoft-Hyper-V -All /LimitAccess /ALL
pause






Sunday, 20 December 2015

Programe to print Pascal Casing of the sentense.....

Step 1:
static void Job32(Args _args)
{
    dialog           dialog;
    dialogGroup      dialogGroup;
    dialogField      dialogField;
    Container        con;
    str              k;
    int              l;
    int              i;
    int              j;
    str              res;
    ;
    dialog            = new Dialog("Simple Dialog");
    //dialogGroup       = dialog.addGroup("Hi");
    dialogField       = dialog.addField(extendedTypeStr(Description),"Enter Description");

    if (dialog.run())
    {
        con = str2con(dialogField.value(),' ',false);
     l = conLen(con);

     for(i=1;i<=l;i++)
     {
            k = conPeek(con,i);
            con = conPoke(con,i,str2CapitalWord(k));
     }

    for(j=1;j<=l;j++)
    {
        //res = conPeek(con,j);
        res = res+" "+conPeek(con,j);
    }

       print res;
       pause;

    }
 }

step 2: Run this job





Result:

Thursday, 19 November 2015

How to export license keys that are already loaded in your system

static void OutputLicenseToText(Args _args)
{
    #define.licenseVersion(2)
    #define.KeywordLen(20)
    #define.keywordLicense('License')
    #define.keywordProperties('Properties')
    #define.keywordCodes('Codes')
    #define.keywordCodeLine('CodeLine')
    #define.keywordDate('Date')
    #define.keywordSerial('Serial')
    #define.keywordValue('Value')
    #define.blank('')
    #define.space1(' ')
    #define.space2('  ')
    #define.space3('   ')
    #define.spaceHash(' #')
    #define.OutputFilename(@'C:\OutputLicenseKeys.txt')

    #define.keywordInfo(1)
    #define.keywordWarning(2)

    SysConfig           sysConfig;
    SysLicenseCodeSort  sysLicenseCodeSort;
    container           fileOut;
    int                 i;
    System.IO.StreamWriter  sw;
    InteropPermission perm = new InteropPermission(InteropKind::ClrInterop);
    ;

    fileOut += "LicenseVersion "    + strfmt("%1", #licenseVersion);
    fileOut += #blank;
    fileOut += #keywordLicense      + #spaceHash + xSysConfig::find(ConfigType::LicenseName,0).Value;
    fileOut += #blank;
    fileOut += #space1  + #keywordProperties;
    fileOut += #space2  + "Name"            + #spaceHash    + xSysConfig::find(ConfigType::LicenseName,0).Value;
    fileOut += #space2  + #keywordSerial    + #spaceHash    + xSysConfig::find(ConfigType::SerialNo,0).Value;
    fileOut += #space2  + #keywordDate      + #spaceHash    + xSysConfig::find(ConfigType::LicenseName,1).Value;
    fileOut += #space1  + "EndProperties";
    fileOut += #blank;
    fileOut += #space1  + #keywordCodes;

    // Build CodeLines
    while select sysConfig
        where sysConfig.configType  == ConfigType::AccessCodes   &&
              sysConfig.value       != #blank
        join sysLicenseCodeSort
        order by SortIdx
        where sysLicenseCodeSort.Id == sysConfig.id
    {
        fileOut += #space2  + #keywordCodeLine  + #spaceHash    + int2str(sysConfig.id + 1);
        fileOut += #space3  + #keywordValue     + #spaceHash    + sysConfig.value;
        fileOut += #space2  + "EndCodeLine";
        fileOut += #blank;
    }

    fileOut += #blank;
    fileOut += #space2  + "EndCodes";
    fileOut += #space1  + "EndLicense";

    // Begin file output
    perm.assert();

    sw = new System.IO.StreamWriter(#OutputFilename);

    for (i=1; i<=conLen(fileOut); i++)
    {
        sw.WriteLine(conPeek(fileOut, i));
    }

    sw.Flush();
    sw.Close();
    sw.Dispose();

    CodeAccessPermission::revertAssert();

    info("License successfully output to " + #OutputFilename);
}
 
Copied From http://www.alexondax.com/2011/01/how-to-export-license-keys-that-are.html
 

Sunday, 1 November 2015

Updating to AX 2012 R3 CU9 step by step with screen shots

1. Download from partner source or customer source.
  • AXUpdateInstaller
  • DynamicsAX2012R3-KB3063879-SlipStreamOnly
http://blogs.msdn.com/b/axsupport/archive/2014/06/04/10288907.aspx

2. Extract zip, then KB
3.Run Ax update in KB folder

4.
5.
6.
7.Follow below link
http://tech.alirazazaidi.com/dynamics-ax-2012-r3-cu9-update-step-by-step/

Put the system for application compilation and generate Full CIL and restart the AOS

8.Press ok
9.
 a. Run 'Detect update scripts'
 b. Before run Presynchronize setup  the server instance from System      administration-->setup-->system--> server configuration 
Select batch server group, as shown
10.Synchronize DataBase

11.Perform remaining tasks
Note:
                  Here only 'application version'will be updated to CU9 but not 'kernel version'. i.e., client needs to be updated. So run CU9 setup again and select "binary updates".
                  Before that  make sure uninstalled visual studio 2010 components and need to install Report viewer 2010


Monday, 12 October 2015

Creating a simple calculator in AX2012

To design above calculator

1.

 2.
method1:
public class FormRun extends ObjectRun
{
    real r;
    real a;
    str k;
    str s;
    real z;
}

method2:
public void init()
{
    super();
    r = 0;
}

3.Override cilcked method of every button

write below code for numbers from 0 to 9
 void clicked()
{
    super();
    r = 10*r+7;
    k = num2str(r,2,2,1,2);
    disply.text(k);
}

 4.For operators write below code
void clicked()
{
    super();
    s="-";
    a = r;
    r = 0;
    disply.text("-");
}

5.For %
void clicked()
{
    super();
    r = r*100/a;
    K = num2str(r,2,2,1,2);
    disply.text(k);

}


6.For = button write below code
void clicked()
{
    super();

    if(s=="+")
    {
        z = a+r;
        K = num2str(z,2,2,1,2);
        disply.text(k);

    }
    else if(s=="*")
    {
        z = a*r;
        K = num2str(z,2,2,1,2);
        disply.text(k);
    }
    else if(s=="-")
    {
        z = a-r;
        K = num2str(z,2,2,1,2);
        disply.text(k);
    }
    else if(s=="/")
    {
        z = a/r;
        K = num2str(z,2,2,1,2);
        disply.text(k);
    }
    a = 0;
    r = z;

}
Note: 'disply' is name of stringedit control...

Creation of dynamic timer in AX 2012









1.Create a form
2. Form>design>control>timeedit(Name : realTime)
3.Write form run methods
method1:
void updateRealTime()
{
    realTime.value(timenow());

    // Set a Time Out with the idle flag set to false
    this.setTimeOut(identifierstr(updateRealTime), 1000, false);
}
method2:
void run()
{
    super();
    this.updateRealTime();
}

Note:Here realTime is control name
Refer AOT>Form>tutorial_timer