Thursday, 26 July 2012

"Error executing code: The field with ID '60001' does not exist in table 'RetailStoreTable'."


error : "Error executing code: The field with ID '60001' does not exist in table 'RetailStoreTable'."

Hi I got this error , when I was trying to update data in RetailStore table.To my surprise this field id was not added to RetailStore Table , then why system was checking for this field id : I debugged further and then found that there is one table : RetailConnCreateActionsByField , which is holding these values together : Table RetailStore mapped with fieldId 60001 , hence system was forced to check this field .

Solution : Remove this entry from Table J.

Will be back 

Friday, 20 April 2012

Open AX 2012 in dev environment

Every time , when you open AX 2012 , you need to press CTRL +D , to open the development work space, 
what if you want to open the Development work space directly , Its very simple ,Just go to properties of shortcut of AX 2012 and update the Target values by adding -development , :) 

Monday, 6 February 2012

Get all dimensions available in AX for any given Environment


How to get all dimensions available in any environment , the below job will help us
static void getAllDimension(Args _args)
{
    Counter         idx;
    Dimension       dimension;
    DimensionCode   dimensionCode;
    str             name;
    ;
    for (idx = 1; idx <= dimof(dimension); idx++)
    {
        dimensionCode = Dimensions::arrayIdx2Code(idx);
        name = enum2str(dimensionCode);
        // if (name == 'B') ...
        info(strfmt("%1: %2", idx, name));
    }
}

Request for the permission of type 'SqlStatementExecutePermission' failed.

While running one Job , where I was trying to execute one SQL statement in AX, I got the below stack trace :


Request for the permission of type 'SqlStatementExecutePermission' failed.
(S)\Classes\SqlStatementExecutePermission\demand
(S)\Classes\Statement\executeQuery
(C)\Jobs\test - line 21


So what is the solution for this , Very simple , we need to run this job on Server , So now how to do it :
here is solution , create a menu item of type action, give the object type as Job ,and object name , and set the property Run on as" Server ".

There you go , Problem solved  :) 

Get Database size using X++

How to get size of Database being used by AX ,below job can help you :



static void GetDBSize(Args _args)
{
LoginProperty loginProp;
ODBCConnection conn;
Resultset resultSet, resultSetCount;
Statement statement1, statement2;
str test;
real s;
SysSQLSystemInfo   systemInfo =  SysSQLSystemInfo::construct();

;

 test = strfmt( "SELECT size FROM sys.master_files where name = '%1'",systemInfo.getloginDatabase()  );
loginProp = new LoginProperty();

loginProp.setServer(systemInfo.getLoginServer());
loginProp.setDatabase(systemInfo.getloginDatabase());

conn = new ODBCConnection(loginProp);

statement1 = conn.createStatement();
resultSet = statement1.executeQuery(test);

while (resultSet.next())
{
s = str2int(resultSet.getString(1));
s = s*8 /1024;
info(strfmt("%1  MB",s));
}
}

Wednesday, 18 January 2012

Get all objects from a Project


If you want to get all objects for a given project , the below job will help .

static void listAllObjectosFromProject(Args _args)
{

  ProjName        projName = "Your Project Name";

  ProjectListNode   list = infolog.projectRootNode().AOTfindChild("Shared");

  TreeNodeIterator  ir = list.AOTiterator();
  ProjectNode      pnProj;
  ProjectNode      pn = list.AOTfindChild(projName);

  void searchAllObj(projectNode rootNode)
  {
    #TreeNodeSysNodeType

    TreeNode          childNode;
    TreeNodeIterator      rootNodeIterator;
    ;

    if (rootNode)
    {
      rootNodeIterator = rootNode.AOTiterator();
      childNode = rootNodeIterator.next();
      while (childnode)
      {

        if (childNode.AOTgetNodeType() == #NT_PROJECT_GROUP)
         searchAllObj(childNode);

        else
          info(strfmt("Group :%1 - Object: %2", rootNode.AOTname(), childNode.AOTname()));

        childNode = rootNodeIterator.next();
      }
    }
  }
  ;

  if (pn)
  {
    info(strFmt("Project %1:", projName));
    pnProj = pn.loadForInspection();
    searchAllObj(pnProj);
    pnproj.treeNodeRelease();
  }
  else
    info("Projet objects");
}

Tuesday, 3 January 2012

Filter automatically on Form

Hi , There may be some requirement that we need to have Filter by grid on form available.
One way of achieving this is , Go to Tools -> Options and Mark Filed by grid on default .
The disadvantage of this , all form will have this functionality and System will slow down.
Then , how to enforce this on only selected forms :
Here you go , place the below line of code in Run method of form after Super();

 this.task(2855);

;
 you will have Filter on only that particular form.

Thanks

Logo for New module created in AX


Hi! I have received the following task: Create new module in Dynamics AX and assign image or logo to this module.
Module is created very easy:Go to the AOT > Menus and create new menu.  For example TestMenu.
1.    Add menu item. For example CustTable menu item.
2.    Then create new menu reference in the MainMenu menu:
o    On the MainMenu menu clicks the right mouse button and select New > Menu reference. TheSelect: Menus windows opens.
o    Drag and drop the TestMenu menu from Select:Menus window to the MainMenu.

This is all. The new module have been added. Reopen Dynamics AX application.
The new modules appears without image (to move module on the top position clicks the Microsoft Dynamics AX >View > Navigate Pane Options…):


 Select the TestMenu menu in the AOT, click right mouse button and selectProperties. There are two properties NoramlImage and NormalResource.


In the NormalImage property the file path to the logo could be specified. But if we create product for sell then we can not specify the exact file path because each Customer will have own path.
In the NormalResource property the image id could be specified. It is suitable for our requirements. Let’s add image in Dynamics AX:
1.    Go to the AOT > Resources. Click right mouse button and select Create form file.
2.    Specify the file path and click Open.
The new image resource will be created:


But this resource doesn’t have the resource id or image id property. Even more in the NormalResourceproperty only the resource id of standard image can be specified. Standard image could be review here AOTForms > SysImageResources.
Trick: we will use the NormalImage property and Logo_image_png resource.
Create the following static method:
static client void addImageToModule()
{
TreeNode treeNodeMenu;
;
treeNodeMenu = SysDictMenu::newMenuName(menustr(TestMenu)).parmTreeNode();
if (treeNodeMenu)
{
treeNodeMenu.AOTsetProperty(identifierstr(NormalImage), SysResource::getImagePath(resourcestr(Logo_image_png)));
treeNodeMenu.AOTsave();
}
}
Call this method in the \Classes\Application\startupPost method:

// No SYS code must exist in this method
// If you need the startup command, look in the class SysStartupCmd
void startupPost()
{
;
Class1::addImageToModule();
}

Reopen application.


All the best Description: ;)

Wednesday, 28 December 2011

"An invalid directory structure for Microsoft Dynamics AX was detected"


Running AX 2009 Client raises error: "An invalid directory structure for Microsoft Dynamics AX was detected"
We came across an issue recently where the Microsoft Dynamics AX 2009 Client was installed ,However after deployment when the client is run from the desktop systems we got a pop window with an error and clicking ok closes the client down:


 Error in text:
An invalid directory structure for Microsoft Dynamics AX was detcted. The subdirectory \Client\bin does not exist.

Upon further investigation, when we ran regedit to look at the registry keys created for the AX Client configuration, indeed it had incomplete path to the client\bin folder. The cause of teh error message. The issue occured on any Windows XP/Vista/7/2003 R2/2008/2008 R2 platform whether its 32bit or 64bit. The paths recorded in the registry were:

[HKEY_CURRENT_USER\Software\Microsoft\Dynamics\5.0\Configuration\Original (installed configuration)]
"bindir"="\Client\Bin"
"datadir"="Client\Data"
"directory"="\Client"
and the correct registry paths should have been (on an x64 system):
[HKEY_CURRENT_USER\Software\Microsoft\Dynamics\5.0\Configuration\Original (installed configuration)]
"bindir"="C:\Program Files (x86)\Microsoft Dynamics AX\50\Client\Bin"
"datadir"="C:\Program Files (x86)\Microsoft Dynamics AX\50\Client\Data"
"directory"="C:\Program Files (x86)\Microsoft Dynamics AX\50\Client"
(x86 system):
[HKEY_CURRENT_USER\Software\Microsoft\Dynamics\5.0\Configuration\Original (installed configuration)]
"bindir"="C:\Program Files\Microsoft Dynamics AX\50\Client\Bin"
"datadir"="C:\Program Files\Microsoft Dynamics AX\50\Client\Data"
"directory"="C:\Program Files\Microsoft Dynamics AX\50\Client"
manually modifying the registry keys with correct values, resolves the issue and allows clients to be run without any errors.

Tuesday, 13 December 2011

Find all display methods in a table


One of my colleague asked this question to me ,
I used the class  “SysDicttable” , to start with and it helped .
I came up with the job mentioned below ,


static void getListOfDisplayMethods (Args _args)
{
    SysDictTable dictTable;
    CustTable custtable;
    List methodList = new List(Types::String);
       ListEnumerator enumerator;
       int i;

    ;

   //77 is the ID of Custtable, you can replace this with out tableid/tablename
    dictTable = new SysDictTable(77);


    methodList =dictTable.getListOfDisplayMethods();
    enumerator = methodList.getEnumerator();
    while(enumerator.moveNext())
    {
    info(enumerator.toString());
    i++;
    }
  
    info(strfmt("no of methods %1",i));
     info(strfmt("no of methods %1",dictTable.objectMethodCnt()));

}

Happy DAXING  J

Cannot execute a data definition language command on (). The SQL database has issued an error.,


While Synchronizing the database , some times we get the  following error , without knowing the tables name ,which caused the issue


Run the below job , in order to get the table name
static void forceDbSynchronize(Args _args)
{
    Dictionary              dict;
    int                     idx, lastIdx, totalTables;
    TableId                 tableId;
    Application             application;
    SysOperationProgress    progress;
    StackBase               errorStack;
    ErrorTxt                errorTxt;
    ;

    application = new Application();
    dict = new Dictionary();
    totalTables = dict.tableCnt();
    progress = new SysOperationProgress();
    progress.setTotal(totalTables);
    progress.setCaption("@SYS90206");
    errorStack = new StackBase(Types::String);

    lastIdx = 0;
    try
    {
        for (idx = lastIdx+1; idx <= totalTables; idx++)
        {
            tableId = dict.tableCnt2Id(idx);
            progress.setText(dict.tableName(tableId));

            lastIdx = idx;
            application.dbSynchronize(tableId, false, true, false);
            progress.incCount();
        }
    }
    catch (Exception::Error)
    {
        errorTxt = strFmt("Error in table '%1' (%2)", tableId, dict.tableName(tableId));
        errorStack.push(errorTxt);
        retry;
    }

    setPrefix("@SYS86407");
    errorTxt = errorStack.pop();
    while (errorTxt)
    {
        error(errorTxt);
        errorTxt = errorStack.pop();
    }
}




Thursday, 17 November 2011

Posting General Journal using code


How to do it...

  1. 1. Open AOT and create a new class called JournalPost with the following code (replace 000152_010 with your journal number):
    class JournalPost
    {
    }
    public static void main(Args _args)
    {
    LedgerJournalCheckPost jourPost;
    LedgerJournalTable jourTable;
    ;
    jourTable = LedgerJournalTable::find('000152_010');
    jourPost = LedgerJournalCheckPost::newLedgerJournalTable(
    jourTable,
    NoYes::Yes);
    jourPost.run();
    }
  2. 2. Run the class and notice the Infolog confirming that the journal was successfully posted:

Tuesday, 1 November 2011

Coloring records in a Form

I was working on a request , where user want to have salesorder of having SalesStatus  cancel in Red color ,

I achieved this by overriding method Displayoption of datasource salestable as below :

public void displayOption(Common _record, FormRowDisplayOption _options)
{
    ;
    if(_record.(Fieldnum(salestable,salesstatus)) == SalesStatus::Canceled)
    {
        _options.backColor(WinAPI::RGB2int(255,100,100));
    }
    super(_record, _options);


Hope this will help , thanks
}