Get Standard Information in AX Monday, Jan 19 2009 

What I mean by standard function is, how to get logon user Id, default date or default datetime. I found it little bit hard, so that I’ll post it to make me easier to search

/*get the default user Id*/


/*get the default date */


/*get the default date time*/

utcdatetime utc4, utcNow;


    utc4 = DateTimeUtil::utcNow();

    utcNow = DateTimeUtil ::applyTimeZoneOffset

        ( utc4,



Select query by using connection class Monday, Jan 19 2009 

query in standard Axapta is really limited because I can’t define distinct. Here is the code to define it, but as a note, you need to define it as a server run object.

public client server static void GetBatchListed( itemId _ItemId)


    Connection  conn;

    Statement   stmt;

    ResultSet   R;

    SqlStatementExecutePermission perm;

    str         sql;

    TSWrkInventBatch    TSWrkInventBatch;


    conn = new connection();

    stmt = conn.createStatement();

    sql = “select * from InventBatch IB inner join (“;

    sql += “select distinct c.InventBatchId from Inventsum a inner join InventDim b “;

    sql += “on a.Inventdimid = b.inventdimid “;

    sql += “inner join InventBatch c on b.InventBatchId = c.InventBatchId “;

    sql += “where a.ItemId = %1 and “;

    sql += “c.inventBatchId <> ”) as TBJoin on IB.InventBatchId = TBJoin.InventBatchId”;

    perm = new SqlStatementExecutePermission(strfmt(sql,_ItemId));


    R = Stmt.executeQuery(sql);

    while (


        info( R.getString(fieldnum(InventBatch, InventBatchId)));



Redim Preserve di C# Tuesday, Oct 14 2008 

Karena sempat merasa bosan dengan coding di VB, last few days saya coba” coding di C# 🙂 dan ternyata jauh lebih bebas coding di C# ketimbang di VB. But, sempet bingung dengan how to define redim preserve in c#, and finally I did it. Below is the example code.

string[] MyArray;
string[] temp;

for (i=0;i<length;i++)
temp = new string[i + 1];
if (MyArray != null)
    Array.Copy(MyArray, temp, Math.Min(MyArray.Length, temp.Length));
MyArray = temp;

How to define day name in SQL Server Thursday, Sep 4 2008 

The SQL function that you could use is datename(datepart, date). Datepart is kind of properties that you’d like to use. For example, dw is kind of datepart to define week day, or mm to define month name. Here is the example

select datename(dw, getdate())

The result is


You could try others datepart such as dw, mm, dy, wk, ww. Have a nice try 🙂

Send Mail SQL Server 2005 Tuesday, Aug 26 2008 

SQL 2005 has easier step to send email than SQL 2000 (of course), and hopefully so is SQL 2008. You only need to run the scripts under your msdb database (For example). Please take a look below scripts.

DECLARE @ProfileName VARCHAR(255)
DECLARE @AccountName VARCHAR(255)
DECLARE @EmailAddress VARCHAR(128)
DECLARE @DisplayUser VARCHAR(128)

SET @ProfileName = ‘MyMail’;
SET @AccountName = ‘MyMailAccount’;
SET @SMTPAddress = ‘’;
SET @EmailAddress = ‘’;
SET @DisplayUser = ‘The Mail Man’;

EXECUTE msdb.dbo.sysmail_add_account_sp
@account_name = @AccountName,
@email_address = @EmailAddress,
@display_name = @DisplayUser,
@mailserver_name = @SMTPAddress

EXECUTE msdb.dbo.sysmail_add_profile_sp
@profile_name = @ProfileName

EXECUTE msdb.dbo.sysmail_add_profileaccount_sp
@profile_name = @ProfileName,@account_name = @AccountName,
@sequence_number = 1

After above scripts run well, you could send the email by writing below scripts.

EXEC msdb.dbo.sp_send_dbmail
@subject = ‘My Man’,
@profile_name = ‘MyMail’

If it’s working properly, there will be a message Mail Queued. You also could see the sent status by selecting from tables sysmail_allitems in msdb database.

select sent_status, * msdb.dbo.sysmail_allitems

Have a nice try 🙂

Cute PDF for default printer Saturday, Apr 12 2008 

I have just known that Ms. Office don’t install automatically the Ms. Document Image Writer as their default printer. Actually I don’t know either the version or options that I have to choose. This one is a big problem for Ms. Dynamics SL because some SL screens are using Ms. Document Image Writer as their default printer, such as shipper (40.110.00). If you aware of this one, you should change the default printer directly to your local printer. Another way is, you could install cute PDF, and set it as your default printer. It worked well 🙂

I don’t know why the Ms. Document Image writer didn’t install in their local bulid PC (actually my client is using HP Bulid PC Desktop). It was a simple thing but became a big problem, because we explored it almost a full one day :(. So, luckily I found the answer.

Next Page »