Monday, July 14, 2014

Getting a list of all projects

Question: How can i get a list of all projects in a system?

Answer: Use the code snippet below,

static void MSTA_Utility_ExportAllProjects(Args _args)
{
    #aot
    #properties
    #AviFiles
    SysOperationProgress    progressBar = new SysOperationProgress();

    TreeNode _treeNode;
    TreeNode projectNode;
    TreeNodeIterator iterator;
    int i, a;
    // Initialising progress bar
    progressBar.setCaption("Export To Excel in progress...");
    progressBar.setAnimation(#AviTransfer);

    _treeNode = infolog.projectRootNode();
    _treeNode = _treeNode.AOTfirstChild();

    for(i = 0; i < 2; i++)
    {
        iterator = _treeNode.AOTiterator();
        projectNode = iterator.next();
        while (projectNode)
        {
            progressBar.setText(strfmt("Project %1", projectNode.treeNodeName()));
            if(String::beginsWith(projectNode.treeNodeName(), "MSTA"))
            {
                info(projectNode.treeNodeName()) ;
            }
            projectNode = iterator.next();
            a++;
        }
        _treeNode = _treeNode.AOTnextSibling();
    }

}

Thursday, May 16, 2013

Object Server 01: The license information can not be decoded.

Question:

AX 2012 AOS Service is not starting and I am getting the following error

"Object Server 01:  The license information can not be decoded. "

Answer:
This is mainly because of permissions, I gave admin rights to AOS service account and it worked. 

Sunday, May 5, 2013

data or calculated fields with type 'Record' are not supported

Question:
I am getting an error "data or calculated fields with type 'Record' are not supported".

Answer:
Make sure the table and all related tables does not have any display method returning a record.

Keyboad Mapper

http://sharpkeys.codeplex.com/

Tuesday, April 2, 2013

Dynamics AX 2009 Report libraries to Dynamics AX 2012 SSRS Reports

Question:How can i convert my Dynamics AX 2009 reporting libraries to be usable in Dynamics AX 2012?Answer:In order to use the Reporting Libraries from 2009 in 2012 use the following steps,1- Use the upgrade reports command line that comes with AX 2012 , normally located at C:\Program Files\Microsoft Dynamics AX\60\tools, to upgrade the reporting libraries to current format.

2- Open the business logic project created after the step above , compile and add the business logic to AOT.

3- Open the reporting project and change the business logic to be using the new business logic.


4- Compile the project, add to AOT and deploy to SSRS.

Other Links
1-http://technet.microsoft.com/EN-US/library/hh292607.aspx
2- http://technet.microsoft.com/en-us/library/hh292607.aspx

Wednesday, October 24, 2012

Print Main Menu

Question: How can i print all elements of a main menu.

Answer: Use the following job, 


static void menuPrint(Args _args)
{

    SysDictMenu menu;
    SysExcelWorksheetHelper worksheetHelper;
    SysExcelHelper sysExcelHelper;
    SysExcelWorksheet worksheet;
    str menuToPrint;
    str worksheetName;
    int currentRow = 1;
    str fileName;
    str path;

    void reportLevel(SysDictMenu _sysDictMenu)
    {

        SysMenuEnumerator enumerator;

        if(_sysDictMenu.isMenuReference() || _sysDictMenu.isMenu())
        {
            path += _sysDictMenu.label() + "//";
            enumerator = _sysDictMenu.getEnumerator();
            while (enumerator.moveNext())
            {
                reportLevel(enumerator.current());
            }
        }
        else
        {   currentRow ++;
            worksheetHelper.setCellValue(2, currentRow, _sysDictMenu.label());
            path = "";
        }
    }

    ;

    sysExcelHelper = SysExcelHelper::construct();
    sysExcelHelper.initialize();

    menuToPrint = 'Roster';
    worksheetName = menuToPrint;
    worksheet = sysExcelHelper.addWorksheet(worksheetName);
    worksheetHelper = SysExcelWorksheetHelper::construct(worksheet);
    // Populate the header row with the appropriate field labels and format the columns
    worksheetHelper.addColumn(1, "Path", Types::String);
    worksheetHelper.addColumn(2, "Item", Types::String);
    worksheetHelper.addColumn(3, "Status", Types::String);
    worksheetHelper.addColumn(4, "Assigned To", Types::String);
    worksheetHelper.addColumn(5, "Notes", Types::String);
    reportLevel(SysDictMenu::newMenuName(MenuStr(Roster)));
    worksheetHelper.autoFitColumns();
    worksheetHelper.formatWorksheetTableStyle(sysExcelHelper.getOfficeVersion());


    // Generate the file using the current UTC date time (without the ‘:’ character)
    // since it is not allowed for file names.
    fileName =  "C:\\Windows\\Temp\\ExportToExcel.xlsx";

    sysExcelHelper.save(filename);
    sysExcelHelper.launchExcel();
}

Tuesday, August 28, 2012

Read / Write Files from document handling

Question:
How can you read / writes files from document handling?

Answer:

void fromFolderToDB(FilePath _path)
{
System.IO.DirectoryInfo         dir = new
System.IO.DirectoryInfo(_path);
System.IO.FileInfo[]            files;
System.IO.FileInfo              curFile;
System.Collections.IEnumerator  enumerator;
BinData                         binData;
DocuValue                       docuValue;
;
files = dir.GetFiles(_path);
enumerator = files.GetEnumerator();
while (enumerator.MoveNext())
{
curFile = enumerator.get_Current();
docuValue.clear();
binData.loadFile(curFile.get_FullName());   // get file content
docuValue.File      = binData.getData();
docuValue.FileName  = curFile.get_Name();
docuValue.insert(); // insert into DB
}
}
void fromDBToFolder(FilePath _path)
{
BinData                         binData;
DocuValue                       docuValue;
;
while select docuValue // load From DB
{
binData.setData(docuValue.File);
binData.saveFile(docuValue.FileName); // insert into file system
}
}
Make attention to CodeAccessPermission when reading/writing to file system
and when using CLR inside X++