Tuesday 12 August 2014

How to copy Application and DB backup in ax 2009

Steps to Duplicate AX2009 Server (copy app-folder and database from source AX2009 server to target AX2009 server)

1)      Stop Dynamics AX Windows Service in newly created Test AX Server’s machine
2)      Copy entire Source Live AX Server’s Application-Folder located at
                     (Ex: C:\Program Files\Microsoft Dynamics AX\50\Application)
To know where-about Source Live AX Server App-Folder location
Goto: Start Menu > Administrative Tools > Microsoft Dynamics AX 2009 Server Configuration
See text in Application-File-Location in Tab:[Application Object Server ]
3)      Paste/Replace folders/files into the targeted new AX Test Server’s Application-Folder
                 To know where-about Test AX Server App-Folder location
Goto: Start Menu > Administrative Tools > Microsoft Dynamics AX 2009 Server Configuration
See text in Application-File-Location in Tab:[Application Object Server ]
4)      Take Database Backup in Source Live AX Server’s SQL-Server
5)      Restore Database in targeted Test AX Server’s SQL-Server
6)      Start Dynamics AX Windows Service in newly created Test AX Server’s machine

Monday 11 August 2014

Management Reporter for Microsoft Dynamics ax 2012 R3

We will get an error in the log files as below
2014-07-16 12:11:12Z 7/16/2014 12:11:11 PM - Extracting supporting files for database deployment...
2014-07-16 12:11:12Z 7/16/2014 12:11:11 PM - Beginning database deployment...
2014-07-16 12:11:12Z 7/16/2014 12:11:12 PM - Initializing deployment (Start)
2014-07-16 12:11:12Z 7/16/2014 12:11:12 PM - Initializing deployment (Failed)
2014-07-16 12:11:12Z 7/16/2014 12:11:12 PM - The database deployment failed. Additional information: Could not deploy 
To resolve that follow the process below.
The SQL server is SQL 2014 (12.0.2000).

I found that the management reporter installer in the installation media I got is version 2.1.8001.
I looked online and see that CU9 (2.1.9001.11) is available. I downloaded it and it worked flawlessly.

Monday 4 August 2014

Either the domain\username user does not have permission to alter the databasename object, or the object does not exist.

To resolve this problem, create and then schedule a cube for the user who is not an administrator. To do this, follow these steps:
1.Add the user to the server role. To do this, follow these steps:
Start SQL Server Management Studio, and then specify Analysis Services for the server type.
Right-click the server, and then click Properties.
Click Security, and then click Add.
In the Select Users or Groups box, type the user's ID.
2.Grant the user permission to create databases on the computer that is running Microsoft SQL Server. To do this, follow these steps:
Start SQL Server Management Studio, and then specify Database Engine for the server type.
Expand Security, right-click Logins, and then click New Login.
On the General page, type the Microsoft Windows login name in the Login name box.
Click Server Roles, and then click dbcreator.
Click OK.
3.Grant the user permission to access the stored procedure sp_dts_putpackage. To do this, follow these steps.

Note:-The user must have access to this stored procedure to schedule SQL Server 2005 Integration Services (SSIS) packages.
Start SQL Server Management Studio, and then specify Database Engine for the server type.
Expand Database, and then expand System Databases.
Expand msdb, and then expand Security.
Right-click Users, and then click New User.
Click the lookup button that is next to the Login name box.
Click Browse, and then click the user ID.
In the User Name box, type a name.
In the Database role membership section, click db_dtsadmin and SQLAgentUserRole.
4.Create a SQL Server credential. To do this, follow these steps:
Start SQL Server Management Studio, and then specify Database Engine for the server type.
Expand Security, right-click Credentials, and then click New Credential.
Click the lookup button that is next to the Identity box, and then click the user ID.
In the Credential name box, type a name.
Type the user's password in the Password and Confirm password boxes.
Click OK.
5.Create a proxy account in SQL Server Agent. To do this, follow these steps.

Note:- A proxy account must be created to enable SQL Server Agent to use the credential that you created in step 4. The user can then run scheduled jobs.
Expand SQL Server Agent, right-click Proxies, and then click New Proxy.
In the Proxy name box, type a name.
In the Credential name box, click the credential that you created in step 4.
In the Active to the following subsystems box, click all the subsystems.
Click Principals, and then click Add.
In the Principal Type box, click Msdb role.
In the Available principals list, click SQLAgentUserRole, SQLAgentReaderRole, and SQLAgentOperatorRole.
Click OK.
6.Modify the job that was used to create the cube. Modify this job so that it runs as the new proxy account that you created in step 5. To do this, follow these steps:
Expand SQL Server Agent, and then expand Jobs.
Right-click the job, and then click Properties.
Click Steps, and then click the job step that was used to create the cube.
Click Edit.
In the Run as box, click the proxy account that you created in step 5.
Click OK.

Sunday 3 August 2014

Dialog Events(Modified, lookups ) in AX 2009

i would like to share you how to do look-up filtration , modified method in dialog using dialog class

lookup :

void Fld5_1_lookup()
{
     Formrun                 fr = dialog.formRun();
    object                  Control = fr.controlCallingMethod();

    SysTableLookup          sysTableLookup =
    SysTableLookup::newParameters(tablenum(CEKMasterCostCardTable),  fieldMccId.fieldControl());
    Query                   query = new Query();
    QueryBuildDataSource    queryBuildDataSource;
    QueryBuildRange         queryBuildRange;
    ;


    sysTableLookup.addLookupfield(fieldnum(CEKMasterCostCardTable, AccountNum),false);
    sysTableLookup.addLookupfield(fieldnum(CEKMasterCostCardTable, Name),false);
    sysTableLookup.addLookupfield(fieldnum(CEKMasterCostCardTable, Type),true);
    sysTableLookup.addLookupfield(fieldnum(CEKMasterCostCardTable, Active),false);
    sysTableLookup.addLookupfield(fieldnum(CEKMasterCostCardTable, MccId),false);


    queryBuildDataSource = query.addDataSource(tablenum(CEKMasterCostCardTable));
    queryBuildRange =         queryBuildDataSource.addRange(fieldnum(CEKMasterCostCardTable,AccountNum));
    queryBuildRange.value(queryvalue(fieldCustAccount.value()));


    sysTableLookup.parmQuery(query);
    sysTableLookup.parmUseLookupValue(false);
    sysTableLookup.performFormLookup();
}

modified :
public boolean Fld2_1_modified()
{
    FormCheckBoxControl control = dialog.formRun().controlCallingMethod();
    boolean isFieldModified;
    ;
    isFieldModified = control.modified();
    if(isFieldModified)
    {
        filedChkNewCard.value(0);
        fieldCustAccount.allowEdit(false);
        fieldMccId.allowEdit(false);
    }
    return isFieldModified;
}

dialog:

protected Object dialog()
{

    ;
    dialog = super();

    dialog.caption("Select  One of three below options or cancel");

    dialog.allowUpdateOnSelectCtrl(true);

   fieldChkBlankCard=dialog.addField(Typeid(NoYes),"Create New Blank Cost Card");
   fieldChkSelectedCard=dialog.addField(Typeid(NoYes),"Copy from selected "+cEKMasterCostCardTable.Name+','+cEKMasterCostCardTable.Type+','+cEKMasterCostCardTable.MccId);
   filedChkNewCard=dialog.addField(Typeid(NoYes),"Copy from Other Customer");

    fieldCustAccount    = dialog.addField(typeid(CustAccount)," Customer ID");
    fieldMccId = dialog.addField(typeid(CEKMccId),"MCC ID");
    fieldType=dialog.addField(typeid(str200),"Type");

    fieldText=dialog.addField(typeid(Notes));

    okButton = dialog.formBuildDesign().control('OKButton');

    okButton.enabled(false);

    return dialog;
}

dialogPostRun:

public void dialogPostRun(DialogRunbase  _dialog)
{
    super(_dialog);
    _dialog.dialogForm().formRun().controlMethodOverload(true);
    _dialog.dialogForm().formRun().controlMethodOverloadObject(this);
}

pack:

public container pack()
{
    return connull();
}

unpack:

public boolean unpack(container packedClass)
{
    return true;
}

class delcaration:

class CEKMasterCostCardDialog extends RunBase
{
    DialogField fieldCustAccount;
    DialogField fieldMccId,fieldText,fieldType;
    DialogField fieldChkBlankCard,fieldChkSelectedCard,filedChkNewCard;
    FormBuildCommandButtonControl   okButton;
    CEKMasterCostCardTable cEKMasterCostCardTable;
    str Mcc;
    Dialog          dialog;
}
main:

public static void main(Args args)
{

    CEKMasterCostCardDialog cekMasterCostCardDialog;
    CEKMasterCostCardTable cekMasterCostCardTable;
    ;

    cekMasterCostCardDialog = new   CEKMasterCostCardDialog();

    if(cekMasterCostCardDialog.prompt())
    {
    cekMasterCostCardDialog.run();
    }
}
http://msdax.blogspot.in/2007/08/overriding-method-for-control-in-dialog.html

http://dynamicsaxsolutionsworld.blogspot.in/2010/12/override-event-methods-on-dialog.html

Call menu item name in ax 2012

Calling the manu item name in form initiation

Form init method()
element.args().menuItemName() == menuitemDisplayStr(GPI_CopyProduct)

validate check with winapi:-
boolean validate()
{
boolean ret;

ret = super();

if(!winapi::fileExists(filenameOpen))
ret = checkFailed(strfmt("@SYS18678",filenameOpen));

return ret;
}

Date functions in ax 2012

static void date_Functions(Args _args)
{
    Transdate    d;
    ;
   
    d = today();
   
    info(strfmt("Date - %1",d));
   
    //Gets the month for the given date...
    info(strfmt("Month - %1",mthofYr(d)));
   
    //Gets the month name from the given date...
    info(strfmt("Month Name - %1",mthname(mthofYr(d))));
   
    //Gets the day for the given date...
    info(strfmt("Day - %1",dayOfMth(d)));
   
    //Gets the day name from the given date...
    info(strfmt("Day Name - %1",dayname(dayOfMth(d))));
   
    //Gets the year for the given date...
    info(strfmt("Year - %1",year(d)));
   
    //Gets the current weekday number from the date...
    info(strfmt("Weekday number - %1",dayOfwk(d)));
   
    //Gets the day of the year from the given date...
    info(strfmt("Day of year - %1",dayOfyr(d)));
   
    //Gets the week of the year from the given date...
    info(strfmt("Week of the year - %1",wkofyr(d)));
}

Copying License in Dynamics Ax

Axapta stores the License data in the following two tables.

1.SysLicenseCodeSort
2.SysConfig

So if you copy data of these tables(from Running instance) and import at your instance

AX2012: Error when downgrading the AX server kernel Object Server 01: 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."

Description: It can happen that you need to downgrade the AOS kernel in a system. Depending on the build you are going back to, you might get an error message.
Error message:

Object Server 01:  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 (4/1). Use a newer
Microsoft Dynamics AX kernel."

Solution:

You need to change the value for the column value SYSTIMEZONESVERSION in the table SQLSystemVariables. If you look in
the event viewer you can see that it finds the value 4, but expected 1 (4/1).
So the solution is to change the value to 1.

Get sql statement form the select statement ax 2012 R2

static void SR_getSQLStatement(Args _args)
{
    CustTable custTable;
    CustTrans custTrans;
    ;
    select generateonly firstOnly AccountNum, CustGroup from custTable
                           join custTrans where custTrans.AccountNum == custTable.AccountNum;
    info(custTable.getSQLStatement());
}
public void executeQuery()
{
   Query q;
   QueryBuildDataSource qbds;
   ;
   q = this.query();
   qbds = q.dataSourceName("PurchTable"); //Replace with the       current Table
   info( qbds.toString() );
   super();
}

Request for the permission in ax 2012 R2

InteropPermission permission;
try
{
permission = new InteropPermission(InteropKind::ClrInterop);
permission.assert();
CodeAccessPermission::revertAssert();
}
catch(Exception::CLRError)
{
    // Get the CLR error before any other CLR operation
   errorMessage = AifUtil::getClrErrorMessage();
   CodeAccessPermission::revertAssert();
   throw error(errorMessage);
}
or
Error: “Request for the permission of type ‘InteropPermission’ failed.”

Many times we would like to call method from dot net assemblies (or) com so we have to assign permission to execute the code .below are ways can be used for CLR and COM

Assign permissions to execute the code (CLR Interop). Like this:

InteropPermission permission = new InteropPermission(InteropKind::ClrInterop);
;
permission.assert();

Assign permissions to execute the code (COM object). Like this::

InteropPermission permission = new InteropPermission(InteropKind::ComInterop);
;
permission.assert();

Microsoft SQL Shedule Backup

Step 1: Open Object explorer in SQL and select “Management” ---> Maintenance Plans
Step 2: Create a new maintenance plan for Shedule Backup
Step 3: A new window pops up and asking for the name of the plan.
Step 4: Once entered, another new window opens
Step 5:  On the Top Left corner (Marked by red color box), from the Maintenance Plan Tasks, select “Back up Database Task”.?
Step 6: Drag and drop “Back up Database Task” to Design part
Step 7:  Double click the Box and a window opens as follows:
Step 8: Select the Database to be taken back up
Step 9: Select the folder where the database has to be taken back up  and also enter the frequency when the database back up has to take place.

Disable UAC on Windows 2012 R2

cmd-> (Regedit)

You have the option to turn off UAC via registry by changing the DWORD “EnableLUA” from 1 to 0 in “HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\policies\system”.
(or)

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\policies\system /v EnableLUA /t REG_DWORD  /d 0 /f

You will get a notification that a reboot is required. After the reboot, UAC is disabled.

https://community.dynamics.com/ax/b/yetanotherdynamicsaxblog/archive/2014/01/09/disable-uac-on-windows-2012-r2.aspx
http://www.mahmoudthoughts.com/2013/12/disable-user-account-control-in-windows.html

AOS takes a long time to start in Ax 2012 R2

Problem:
When you start an AOS, you may notice it takes a very long time before the service gets the status “Started”. A possible cause is left-over data in SysClientSession table. When starting up, the AOS seems to check if the client is still around.  The SysClientSessions contains the data for the client sessions that are currently active in the system.

Solution:
1. Shut down AOS for sing instance or all AOSes for multiple instances (not an ideal way in Production)
2. Use SQL Server Management Studio and run this sql
SELECT        SESSIONID, SERVERID, VERSION, LOGINDATETIME, LOGINDATETIMETZID, STATUS, USERID, SID, USERLANGUAGE, HELPLANGUAGE, CLIENTTYPE,
SESSIONTYPE, CLIENTCOMPUTER, DATAPARTITION, RECVERSION, RECID
FROM            SYSCLIENTSESSIONS

DELETE  FROM SYSCLIENTSESSIONS;
3. Delete all client records
4. Restart AOS(es)