Read and Modify registry settings in Ax

Source : http://colorsofaxapta.spaces.live.com/blog/cns!FB14F6851EBD172E!117.entry

Here is a sample code of increasing max. open cursors during run-time. But, please note that its purpose is only to show you how to read and write registry. If you encounter any open cursors problem, it is recommended to optimize the SQL statement rather than changing the setting for maximum open cursors.

static void IncreaseMaxOpenCursors(Args _args)
{
    #winapi
    container   regRet;    
    int         readReg;
    int         writeReg;
    str         keyValue, keyPath, configName;
    int         maxOpenCursors;
    ;
 
    //Specify your Axapta configuration utility name here
    configName = "LocalMachine";
    //New maximum open cursor, default is 90
    maxOpenCursors = 120;
    keyPath = @"SOFTWARE\Navision\Axapta\3.0\" + configName;
    readReg  = WinAPI::regOpenKey( #HKEY_CURRENT_USER, keyPath, #KEY_READ);
    if (readReg)
    {
        regRet = WinAPI::regGetValue(readReg, 'opencursors');
        keyValue = conpeek(regRet,1);
        info(keyValue);
        if (str2int(keyValue) < maxOpenCursors)
        {
            writeReg  = WinAPI::regOpenKey(#HKEY_CURRENT_USER, keyPath, #KEY_WRITE);
            if (writeReg)
            {
                WinAPI::regSetValueEx(writeReg, 'opencursors', #REG_SZ , maxOpenCursors);
                WinAPI::regCloseKey(writeReg);
            }
            Info("Max open cursors: " + int2str(maxOpenCursors));
        }
        WinAPI::regCloseKey(readReg);
    }
}
Advertisements

Print PDF file to printer

Source : Palle Agermark on AX

ATTENTION : That’s work ONLY if you have Adobe Reader installed !

Just write this code (and adapt) :

static void pdfprint(Args _args)
{ 
    str                 adobeExe; 
    str                 adobeParm; 

    PrintJobSettings    printJobSettings = new PrintJobSettings(); 
    Dialog              dialog = new Dialog(); 
    DialogField         dialogFileName; 
    ;
    dialogFilename  = dialog.addField(typeid(FilenameOpen));

    if (dialog.run()) 
    {     
        printJobSettings.printerSettings('SysPrintForm');     
        adobeExe = WinAPI::findExecutable(dialogFileName.value());
       
        adobeParm = strFmt(' /t "%1" "%2" "%3" "%4"',
                           dialogFileName.value(),
                           printJobSettings.printerPrinterName(),
                           printJobSettings.printerDriverName(),
                           printJobSettings.printerPortName());

        WinAPI::shellExecute(adobeExe,  adobeParm); 
    }
}