Posts

Send message or alert to all online users

In Axapta 2.5 or 3.0, there is a standard function to send message to all online users. But it has been taken away after AX 4.0. However you still do this by some codes: static void sendAlertToOnlineUsers(Args _args) { EventInbox inbox; EventInboxId inboxId; SysClientSessions sessions; ; while select sessions where sessions.Status == SessionState::Running { inboxId = EventInbox::nextEventId(); inbox.initValue(); inbox.ShowPopup = NoYes::Yes; inbox.Subject = "GIT TESTING ALERT MESSAGE"; inbox.Message = "HELLO?"; inbox.SendEmail = false; inbox.UserId = sessions.userId; inbox.InboxId = inboxId; inbox.AlertCreatedDateTime = DateTimeUtil::getSystemDateTime(); inbox.insert(); } }

SQL script to truncate and shrink log file of all database

This is a quick method to truncate and shrink the log file of all database. I usually use for clean up development database. declare @ssql nvarchar(4000) set @ssql= ' if ''?'' not in (''tempdb'',''master'',''model'',''msdb'') begin use [?] declare @tsql nvarchar(4000) set @tsql = '''' declare @iLogFile int declare @sLogFileName varchar(55) declare LogFiles cursor for select fileid from sysfiles where status & 0x40 = 0x40 open LogFiles fetch next from LogFiles into @iLogFile while @@fetch_status = 0 begin set @tsql = @tsql + ''DBCC SHRINKFILE(''+cast(@iLogFile as varchar(5))+'', 500) '' fetch next from LogFiles into @iLogFile end set @tsql = ''USE [?]; '' + @tsql + '' BACKUP LOG [?] WITH TRUNCATE_ONLY '' + @tsql --print @tsql --for debugging exec(@tsql) close LogFiles DEALLOCATE LogFiles end' exec sp_msforeachdb @ss...

What images are available for the NormalResource Property

It is under: Microsoft Dynamics AX menu > Tools > Development tools > Embedded resources. The window displays the available images, and the Resource ID of each image.

Temporary tables in forms

Using temporary tables in forms requires the use of the .setTmpData() method. For example: The temporary table data is populated in a static class method (running server side), which is called from the form and returns the populated table. We could populate a form-level buffer with the temporary data if needed, or else just call the populating method directly from the setTmpData() call as shown below. In the form datasource init(), we use .setTmpData() to instruct the datasource query to use our temporary table. Our datasource name in this example is TempTable. public void init() { super(); TempTable.setTmpData(tmpTableClass::populateTmpData()); }

Send email by using SysMailer

There are several methods to send email in Axapta. Using SysMailer is one of those. Method 1 (Normal): static void Email1(Args _args) { SysMailer mailer = new SysMailer(); ; mailer.quickSend("mike@abc.com","mike@abc.com","subject","body"); } Method 2 (Simple): static void Email2(Args _args) { SysMailer mailer = new SysMailer(); SysEmailParameters parameters = SysEmailParameters::find(); ; if (parameters.SMTPRelayServerName) { mailer.SMTPRelayServer(parameters.SMTPRelayServerName, parameters.SMTPPortNumber, parameters.SMTPUserName, SysEmailParameters::password(), parameters.NTLM); } mailer.fromAddress("mike@abc.com"); mailer.tos().appendAddress("mike@abc.com"); mailer.htmlBody("hi"); mailer.sendMail(); }

Post packing slip of sales order in X++

SalesFormletter SalesFormletter; SalesTable SalesTable; ; SalesFormletter = SalesFormletter::construct(DocumentStatus::Confirmation,true); SalesTable.clear(); SalesTable = SalesTable::find(_salesId); SalesFormletter.update(SalesTable, systemDateGet(), SalesUpdate::All, AccountOrder::None, false, false);

GetSystemDateTime() difference

Situation: I tried to update a datetime value of a external database to let say GetSystemDateTime(). However, it was found that the time updated was not equal to GetSystemDateTime(). Solution: It is because of time zone problem. In AX 2009, datetime is stored in UtcDateTime format. During presentation, the offset timezone of the user option is calculated. So you can make use of the following code to update datetime DateTimeUtil::applyTimeZoneOffset(datetimeutil::getSystemDateTime(), DateTimeUtil::getUserPreferredTimeZone());