Sunday, June 26, 2011

To create a Directory Path (X++)

Hi,

To create a particular Dicetory path using X++, follow below code steps:

protected boolean createDirectoryPath(FilePath _path)
{
    int ptr;
    ;
    try
    {
        //First check for the passed path exits or not
        if (winAPI::folderExists(_path))
        {
            return true;
        }

        _path = strLRTrim(_path);

        if (substr(_path,strlen(_path),1) != '\\') //Adding backslash gives a more simple while-loop!
        {
            _path += '\\';
        }

        //MKU: enables creation of UNC paths, by detecting which folder already exists (backwards).
        ptr = strLen(_path);
        ptr = strfind(_path, '\\', ptr, -ptr);
        while(!WinAPI::folderExists(substr(_path,1,ptr)))
        {
            ptr = strfind(_path, '\\', ptr -1 , -ptr);
        }
        // ptr now points to last existing folder in the path.
        //MKU: end

        while (ptr)
        {
            WinAPI::createDirectory(substr(_path, 1, ptr));
            if (!WinAPI::folderExists(substr(_path, 1, ptr)))
            {
                break;
            }
            ptr = strfind(_path, '\\', ptr + 1, strlen(_path));
        }

        return WinAPI::folderExists(_path);
    }
    catch
    {
        info('@WML75'); //Item image is not created.
        return false;
    }
}

Thanks,
/Ashlesh

Ax Directory Path X++

 Hi,
 Below are the useful paths.

To get Axapta directory path:

xinfo::directory(directorytype::Temp);
xinfo::directory(directorytype::appl);

To get local directory temp path:
WinApi::getTempPath()

Thanks.

Thursday, June 23, 2011

Find the difference between two Times

Hi,

Using below code find the difference between two time values,

static void DateTimeDifference(Args _args)
{
    UTCDateTime abcdatetime;
    ;
    sleep(5000);
    info(strfmt("Difference: %1",DateTimeUtil::getDifference(DateTimeUtil::getSystemDateTime(),abcdatetime)));
}

To Create a new company - Demo data in AX 4.1 and above

Hi,
I found a very good article from 'dynamicsaxaptatraining' website. I have copied the link for that below.

How to create demo data for a new company in AX?

This also contains the link to download the Demo Data.

Thanks,
/Ashlesh

Tuesday, June 21, 2011

Set the Dialog in Center of the screen

To set the dialog to center of the screen,

static void dialogShowAtCenter(Args _args)
{
Dialog dlg = new Dialog("Dialog");
;

dlg.addText("This dialog is shown in the center of the screen.");

dlg.dialogForm().form().design().left(44, 4); //center
dlg.dialogForm().form().design().top(220, 3); //center

dlg.run();
}

Monday, June 6, 2011

To store an image to as container data type in a table

Hi,

To store the image to a continer datatype in a table a sample code unit is as below:
display Bitmap bitmap()
{
   Bitmap bitmap;
   Bindata     binData = new BinData();

if (binData.loadFile('c:\\1.bmp'))
   {
       bitmap = binData.getData();
   }
   return bitmap;
}
 
Thanks,
/Ashlesh 

Tuesday, May 24, 2011

To pad the string in AX 2009

Hi,
To pad the special char to end/start of the string follow below function,
client server public static str StrLFix(
    str _str, 
    int _length, 
   [char _char])
 
And 
client server public static str StrRFix(
    str _str, 
    int _length, 
   [char _char]) 
 
Regards,
/Ashlesh