Skip to main content

Posts

Showing posts with the label Write

Write into the System Event Viewer from Dynamics AX

This is a very short article which shows how to write any information into the system event viewer. This is something that can be very useful when trying to debug processes such as batches that are difficult to debug. One thing to note is that if the code is running on the AOS the information will be written to the EventViewer on the AOS, just something to keep in mind if you don’t see your message in the EventViewer. static void writeEventLogEntry(Args _args) { System.Diagnostics.EventLog eventlog; #Define.LogSource( "Dynamics AX" ) #Define.LogName( "Application" ) ; // check if the log already exists if (!System.Diagnostics.EventLog::SourceExists(#LogSource)) { // create new log System.Diagnostics.EventLog::CreateEventSource(#LogSource, #LogName); } eventlog = new System.Diagnostics.EventLog(); eventlog.set_Source(#LogSource); // write info entry eventlog.WriteEntry( " : Just writing in the event viewer." ); // write error entry eventlog.Write...

Dynamics AX - code to Read/Write data to excel

Writing Data to Excel file How it works 1. Use SysExcelApplication class to create excel file. 2. Use SysExcelWorkbooks and SysExcelWorkbook to create a blank workbook(by default 3 worksheets will be available). 3. Use SysExcelWorkSheets to select worksheet for writing data. 4. SysExcelCells to select the cells in the excel for writing the data. 5. SysExcelCell to write the data in the selected cells. 6. Once you done with write operation use SysExcelApplication.visible to open file. static void Write2ExcelFile(Args _args) { InventTable inventTable; SysExcelApplication application; SysExcelWorkbooks workbooks; SysExcelWorkbook workbook; SysExcelWorksheets worksheets; SysExcelWorksheet worksheet; SysExcelCells cells; SysExcelCell cell; int row; ; application = SysExcelApplication::construct(); workbooks = application.workbooks(); workbook = workbooks.add(); worksheets = workbook.worksheets(); worksheet = worksheets.itemFromNum(1); cells = worksheet.cells(); cells.range('A:A').nu...

Dynamics AX 2009: Write to eventlog entry

Our client requested to keep track of all Dynamics AX system errors during the User Acceptance Testing. I use the application event logs to store the information. The following code shows you how to write event log entry with X++: Create a new class AX_EventLog with a static method WriteEventLog : static void WriteEventLog(Exception _exception, str _event) { str eventSource = " AX event "; str logType = " Application "; System.Diagnostics.EventLogEntryType eventLogEntryType; int eventCategory = 9999; ; switch (_exception) { case Exception::Info: eventLogEntryType = System.Diagnostics.EventLogEntryType::Information; break ; case Exception::Warning: eventLogEntryType = System.Diagnostics.EventLogEntryType::Warning; break ; default : eventLogEntryType = System.Diagnostics.EventLogEntryType::Error; } if (!System.Diagnostics.EventLog::Exists(eventSource)) { System.Diagnostics.EventLog::CreateEventSource(eventSource, logType); } System.Diagnostics.EventLog::Writ...