Thursday, June 26, 2008

The Enterprise Portal team introduces new blog for Microsoft Dynamics AX 2009

The EP team has just created a blog about their stuff. These guys know their stuff, and are heavy users of managed code interoperability with X++.
Check it out http://blogs.msdn.com/epblog/

Thursday, June 12, 2008

Microsoft Dynamics AX 2009 SDK


Microsoft Dynamics AX 2009 SDK
Together with the release of the actual product, documentation for the Microsoft Dynamics AX 2009 SDK has been released on MSDN. There is a lot stuff there including lots of info on the new EP 2009 framework here. Check it out. Also check out the Microsoft Dynamics AX Developer Center.

Open table or browse from editor code


Many times Developer needs to open the table or browse while coding. Developer has to go to AOT then search for that table. To ease of this situation by following code developer can easily open the table or browse from Editor windows itself.

Copy paste the following methods in EditorScript Class of axapta
//------------------------
void AX_openTable(Editor e)
{

#AOT
TreeNode tr;
XInfo xInfo = new xInfo();
str selection;
;
selection= strltrim((strrtrim(Editorscripts::getSelectedText_n(e)))); // modified standard method getSelectedText
tr = TreeNode::findNode(#TablesPath + '\\'+selection);
if(tr)
tr.AOTnewWindow();
else
Throw error(strfmt("Table %1 not found",selection));

return;

}

//----------
static str getSelectedText_n(Editor e)
{
int i;
str text;
str line;
int startLine = e.selectionStartLine()+1;
int endLine = e.selectionEndLine()+1;
int startCol = e.selectionStartCol();
int endCol = e.selectionEndCol();

if (startLine == endLine && startCol == endCol)
{
e.firstLine();
while (e.moreLines())
{
text += e.getLine();
e.nextLine();
}
}
else
{
e.firstSelectedLine();
for (i = startLine; i <= endLine; i++)
{
line = e.getLine();
if (i == startLine && i == endLine)
{
line = substr(line, startcol, endCol-startCol);
}
else
if (i == endLine)
{
line = substr(line, 1, endCol-1);
}
else
if (i == startLine)
{
line = strrep(' ', startCol-1)+substr(line, startCol, strlen(line));
}

text += line;
e.nextSelectedLine();
}
}
return text;
}

//---------
To Browse the Table Add
//-------
void AX_browseTable(Editor e)
{

#AOT
TreeNode tr;
TableId TableId;
XInfo xInfo = new xInfo();
str selection;
SysTableBrowser SysTableBrowser;
;
selection= strltrim((strrtrim(Editorscripts::getSelectedText_n(e)))); // modified standard method getSelectedText
tr = TreeNode::findNode(#TablesPath + '\\'+selection);
if(tr)
{
TableId = tablename2id(selection);
if(TableId)
new SysTableBrowser().run(tableID);
}
else
Throw error(strfmt("Table %1 not found",selection));

return;

}

Wednesday, June 11, 2008

Data Authorization in axapta through coding

Data authorization in Microsoft Dynamics AX is performed in three ways:
1.Implicit Authorization
Implicit authorization means that the kernel performs the check. An example of this would be when you are accessing a data source from a form or report. Record level security is used to determine whether the user has access to run the form or report.
2.Checks Done by Setting Security Properties on AOT Objects
An example of this is setting the security key and needed access level properties on menu items and on form or report controls.
3.Checks done in X++
Examples:
if (hasSecurityKeyAccess(securitykeyNum(mySecurityKey), AccessType::View))
{
myMethod();
}

if (hasMenuItemAccess(menuItemDisplayStr(myMenuItem), MenuItemType::Display)))
{
myMethod();
}

DictTable dictTable = new DictTable(tablenum(myTable));
if (dictTable.rights >= AccessType::Insert))
{
myMethod();
}

if (isConfigurationkeyEnabled(configurationkeyNum(myConfigurationKey))
{
myMethod();
}

How to print a query name on a report in Axapta

The sysQueryForm form is used to create multiple queries for a report. This form is used by most reports in Microsoft Axapta.

The sysQueryForm form contains a name field. The contents of this name field are printed on the report. However, there is no direct relation between the contents of this name field and the query name.

You can customize Microsoft Axapta to print the query name on the report. To do this, follow these steps:
1. Modify a method to capture the value of the name field. This value holds the query name.
2. Create a method to perform the following tasks:
• Obtain the value of the name field.
• Print this value on the report.


The following code applies to the QueryLoad method. This example code indicates how to modify a method to perform the following tasks:
• Capture the query name.
• Set this variable to a global variable.
switch (_name)
{
case sysQueryForm.queryLastUsedLabel():
saveBtn.enabled(false);
deleteBtn.enabled(true);
break;
case sysQueryForm.queryActiveLabel():
saveBtn.enabled(false);
deleteBtn.enabled(false);
break;
default:
saveBtn.enabled(true);
deleteBtn.enabled(true);

// Add the following two lines to display the query name value.
globalCache = classfactory.globalCache();
globalCache.set("Query","ReportQuery",_name);

break;
}

The following code applies to the Display method. This example code indicates how to create a method to perform the following tasks:
• Obtain the value of the name field.
• Print this value on the report.
Display custAccount Queryname()
{
SysGlobalCache globalCache;
Name queryName;
;

globalCache = classfactory.globalCache();
queryName = globalCache.get("Query","ReportQuery",null);

return queryName;
}

How to call Axapta methods from .net

Using .NET Business Connector, you can access Microsoft Dynamics AX data or business logic from a .NET-connected application.
To add a reference to .NET Business Connector
•Open Visual Studio.
•In Solution Explorer, right-click References and select Add Reference.
•In the Add Reference window, select the Browse tab.
•Specify the location of Microsoft.Dynamics.BusinessConnectorNet.dll, and then click Add.
Add code to call a Microsoft Dynamics AX method in Visual Studio C#.
using System;
using Microsoft.Axapta.BusinessConnector;
namespace AXMethodCall
{
class Class1
{
static void Main(string[] args)
{
// Create the .NET Business Connector objects.
Axapta ax;
object o;
bool b;
try
{
// Login to Microsoft Dynamics Ax.
ax = new Axapta();
ax.Logon(null, null, null, null);
}
catch (Exception e)
{
Console.WriteLine("An error occurred in object creation or Axapta logon: {0}", e.Message);
return;
}
// Logon was successful.
try
{
// Call a static class method.
o = ax.CallStaticClassMethod("Class Name ", "Method Name",Argument);
}
catch (Exception e)
{
Console.WriteLine("An error has been encountered during CallStaticClassMethod: {0}", e.Message);
b = ax.Logoff();
return;
}
// Log off from Microsoft Dynamics AX.
b = ax.Logoff();
}
}
}

Block Comment in axapta Editor Script(class)

To Comment a code axpta in a Block Like
/*
Some Code
*/
Add the Below Code in Editor Scripit Class in Axapta

void AX_BlockComment(Editor e)
{
int FLine,Eline;
int FCol,ECol;


FLine = e.selectionStartLine();
FCol = e.selectionStartCol();

ECol = e.selectionEndCol();
Eline = e.selectionEndLine();
e.unmark();

e.gotoLine(FLine-1);
e.gotoCol(1);
e.insertLines('//'+' Commented by ' + curUserId()+', on '+date2str(today(),123,2,1,3,1,4 ) + ',' +time2str(timeNow(), 1, 2)+'\n');

e.gotoLine(FLine);
e.gotoCol(FCol);
e.insertString('/*');

e.gotoLine(Eline+1);
e.gotoCol(1);
e.insertString('*/');


}

Send Alert to user from code in AX 4.0

// To send Alert to User From Code
void sendAlertToUsers()
{
SysMailer mail;
UserInfo UserInfo;
EventInbox inbox;
EventInboxId inboxId;
;

select UserInfo where UserInfo.id == CurUserId();
inboxId = EventInbox::nextEventId();

inbox.initValue();
inbox.ShowPopup = NoYes::Yes; // To show Pop up
inbox.Subject = "Aleart Message Through Code";
inbox.Message = "Testing Alerts";
inbox.AlertedFor = "This alert is just for information(Testing)";
inbox.SendEmail = false;
inbox.UserId = UserInfo.Id;
inbox.TypeId = classnum(EventType);
//Enter Table and Field Details
inbox.AlertTableId = TableNum(EmplTable); // Table for which Alert is Generated
inbox.AlertFieldId = fieldNum(Empltable ,Name); // Field for which Alert is Generated
inbox.TypeTrigger = EventTypeTrigger::FieldChanged;
inbox.CompanyId = CurExt();
inbox.InboxId = inboxId;
inbox.AlertCreatedDate = systemdateget();
inbox.AlertCreateTime = timeNow();
inbox.insert();
}