Skip to main content

Posts

Showing posts from March, 2013

Failed to create session in MSD AX 2012.

Hello J I found one more strange issue today, when I tried creating SO (Sales order) an error prompts:
Failed to create a session; confirm that the user has the proper privileges to log on to Microsoft Dynamics.
Also I heard error arrives many times at different times in AX 2012 like when processing journal, Creation of purchase order, catalog etc...
And here is the solution:
The solution is to unchecka checkbox in Options at Tools > Options > Development > General > Execute business operations in CIL
Purpose of this checkbox (“Execute business operations in CIL” or not?) In AX 2012, steps are taken by the development team at Microsoft to align AX IDE with .NET. That’s why you regenerate the CIL after X++ code changes.
CIL obviously has its benefits like faster execution in cases of heavy logic processing. But sometimes while testing or debugging, developers would prefer NOT to avail this option. Debugging can be cumbersome in AX 2012 as you will need to configure Visual Studio for…

Copying data from notepad to Dynamics AX

Hi friendsJ, Let me discuss a very simple customization wherein you would be required to fetch or bring the data which lies in your copy (ctrl + c).
Let’s say in your notepad there is data “MS Dynamics AX2012” Now just copying this data through ctrl +c and my requirement is to get this data somewhere in AX form.
static void ToGetDataLiesinCopy(Args _args) {     str         ret;     TextBuffer  tb;     ;
    tb = new TextBuffer();     tb.fromClipboard();
    ret = tb.getText();
    info(ret);
}
This is just a dummy example; there can be a situation wherein you need range from notepad to AX forms like “itemid” range or customer range, so this example would suit your requirement. I’ll be back with some more. Thanks for Daxing JJ

To fetch IP address of system through X++

static void FetchIpAddress (Args _args) { System.String                       hostName = System.Net.Dns::GetHostName(); System.Net.IPHostEntry              hostEntry = System.Net.Dns::GetHostEntry(hostName); System.Net.IPAddress[]              addresses = hostEntry.get_AddressList(); System.Net.IPAddress                address; System.Net.Sockets.AddressFamily    addressFamily; System.Collections.IEnumerator      enumerator = addresses.GetEnumerator();
while (enumerator.MoveNext()) {     address = enumerator.get_Current();     addressFamily = address.get_AddressFamily();     if (addressFamily == System.Net.Sockets.AddressFamily::InterNetwork)     {         info(address.ToString());     } } }

Form open through X++ code / Go to main table form

Hello guys J let me cover a very short topic on how to open a form in MS Dynamics Ax by code.

Sometimes it is very essential to open a form (or) intermediate form through code in AX. Or when we implement the functionality of “Go to main table”, we can use X++ code to open the form.
In the direct example, all it takes is one line of code.

new MenuFunction(MenuItemDisplayStr(CustTable),MenuItemType::Display).run();

The above code will open the CustTable form. This is as simple as it looks.
Now if we want to supply some arguments to the opening form, this is also possible with the optional args parameter.
Let us observe this with quick example:
static void FormopenthroughCode()
{ Args args = new Args();
;
args.record(CustTable::find('CUS-0001'));
new MenuFunction(MenuItemDisplayStr(CustTable),MenuItemType::Display).run(Args);
}

This code will open the CustTable form and filter out the customer with accountnumber CUS-0001.
Use the args methods like parm and parmEnum to provide your…

“No device” error on AX Client startup

Hi EveryoneJ!!


Today I came across one weird issue while opening AX2009; it was never an issue before.


This error message is caused by the ActiveX component for the phone integration on form smmPhone which returns an error for each phone device which is offline. 
In order to prevent the error message, just edit the code in smmForm, here is the path \Forms\smmPhone\Designs\Design\ActiveX:axPhone\Methods\onEvent_TapiError
What is TAPI??
TAPI (Telephony Application Programming Interface) is a Microsoft Windows standard interface for integration between telephone systems and windows based software. A typical example is integrating called ID with a database on your computer that contains detailed information about potential callers. When your phone rings, a window pops up
on your computer with information about the caller. This is possible through software applications that are TAPI compliant and support the Screen Pop and Auto-Dialer capabilities.

You can do the following code changes to preve…

Ledger postings in MS Dynamics AX 2009

PS stands for packing slip PSO stands for packing slip offset
Ledger postings for sales order:
1.packing slip:                                                                                      Credit             Debit                         Inventory clearing … shipped, Un invoiced (PS)…………. Cr Account Receivable clearing (PSO)………………………………………….……….Dr 2.Sales Invoice: Inventory clearing … shipped, Un invoiced (PS)……………………………….Dr Account Receivable clearing (PSO)………………………………..Cr Sales order (inventory) Issue………………………………….……..Cr Sales order (Inventory) consumption……….........................................Dr Customer balance………………………………………………..............................Dr Revenue………………………………………………………………........Cr               3.payment:         Bank or cash…………………………………………………………………….................Dr Customer Balance…………………………………………………….....Cr
Ledger postings for purchase order:
1. Packing slip: Inventory clearing…Received (PS)……………………………………………………Dr Accounts Payable clearing (PSO)……………………………………

Force Synchronisation of AOT tables through X++ in AX:

static void forceDbSynchronize1(Args _args)
{
Dictionary dict;
int idx, lastIdx, totalTables;
TableId tableId;
Application application;
SysOperationProgress progress;
StackBase errorStack;
ErrorTxt errorTxt;
; application = new Application();
dict = new Dictionary();
totalTables = dict.tableCnt();
progress = new SysOperationProgress();
progress.setTotal(totalTables);
progress.setCaption(“@SYS90206″);
errorStack = new StackBase(Types::String); lastIdx = 0;
try
{
for (idx = lastIdx+1; idx <= totalTables; idx++)
{
tableId = dict.tableCnt2Id(idx);
progress.setText(dict.tableName(tableId)); lastIdx = idx;
application.dbSynchronize(tableId, false, true, false);
progress.incCount();
}
}
catch (Exception::Error)
{
errorTxt = strFmt("Error in table '%1' (%2)", tableId, dict.tableName(tableId));
errorStack.push(errorTxt);
retry;
} setPrefix("@SYS86407");
errorTxt = errorStack.pop();
while (errorTxt)
{
error(errorTxt);
errorTxt = errorStack.pop();
}
}

Get exchange rate from web in to MS AX

static void GetExchangeRates(Args _args) {     com com = new com('microsoft.xmlhttp');     com com1;     XMLDocument xmlDoc;     Dialog exchDialog = new Dialog("Exchange Rates");     DialogField   fromField;     DialogField   ToField;     str                 url;     ;
    fromField = exchDialog.addField(typeid(currencycode), 'Base Currency');
    fromField.value(CompanyInfo::find().CurrencyCode);
    ToField =  exchDialog.addField(typeid(currencycode), 'To Currency');
    if(exchDialog.run())     {         url = "http://www.webservicex.net/CurrencyConvertor.asmx/ConversionRate?";         url += "FromCurrency=" +strupr(fromField.value())+"&ToCurrency="+strupr(ToField.value());         com.open("get",url, false);         com.send();         com1 = com.responsexml();         xmlDoc = XmlDocument::newXml(com1.xml());
        info("1"+fromField.value() + " = " +xmlDoc.getNamedElement('double').text() + &q…

X++ Code to Export AOT Object / automatic backup of XPO's.

Hi friends, hope all is well!! J
Today am here to convey the most vital subject for MS dynamics AX.
Development or customization's are the most important topic which should be saved or backup need to be taken on daily or weekly basis.
We need to take daily backup of our development (in terms of XPO), but we all always forget because of our hectic work schedules.
So use the following job and build batch application to take backup of development in terms of XPO. We can take AOD file also but the size will be more and needs to stop AOS every time.
Following job illustrates how to export/backup all AOT Classes object.
void ExportTreeNodeExample() {     TreeNode            treeNode;     FileIoPermission    perm;
    #define.ExportFile(@"D:\AOTclasses.xpo")     #define.ExportMode("w")     ;
    perm = new FileIoPermission(#ExportFile, #ExportMode);     if (perm == null)     {     return;     }     perm.assert();
    treeNode = TreeNode::findNode(@"\Classes");     if (treeNode …

Lookup (or) Drop-down for field in Dynamic AX using query

void lookupField(FormControl  control)
{
    Query                   query = new Query();
    QueryBuildDataSource    queryBuildDataSource;
    QueryBuildRange         queryBuildRange;
    SysTableLookup          sysTableLookup;
    ;

    //Create an instance of SysTableLookup with the form control passed in
    sysTableLookup = SysTableLookup::newParameters(tablenum(<table name>), control);

    //Add the fields to be shown in the lookup form
    sysTableLookup.addLookupfield(fieldnum(<table name>, <field name>), true);
    sysTableLookup.addLookupfield(fieldnum(<table name>, <field name>), false);

    //create the query datasource
    queryBuildDataSource = query.addDataSource(tablenum(<table name>));
    queryBuildRange = queryBuildDataSource.addRange(fieldnum(<table name>, <field name>));
    queryBuildRange.value(enum2str(NoYes::Yes)); //Example of Enum value or you can specify any range

    //add the query to the lookup form
    sysTableLookup.parmQ…

Use of container in display method in AX

Hi friends, Today am going to discuss about the use of container in display method in MS dynamics AX. There may be requirement when we need to display certain things from multiple lines in to a single field with comma separated, and it is just for viewing purpose(Sometime informative).
Let us take a quick example wherein I can show you this functionality working and code behind it!! J
Ex: In sales header you want to capture all the lines warehouses in a single field which should be separated in comma. Am going to add display method, Just add the below code in Table > SalesTable
Display Name Warehouse() {     salesline salesline;     Container warehouse;     int i=0;     str strwarehouse;     ;     strwarehouse='';     while select salesline where salesline.SalesId==this.SalesId     {         if(confind(warehouse,InventDim::find(salesline.InventDimId).InventLocationId)==0)             warehouse +=InventDim::find(salesline.InventDimId).InventLocationId;     }      for (i = 1 ; i <= conLen(wa…

To find stock On-Hand in AX through X++

static void findOnHand(Args _args)
{

InventDim inventDim;
InventDimParm inventDimParm;
Itemid itemid;
InventOnHand inventOnHand = new InventOnHand();
;

// take a sample item for testing
itemid = "Item1";

// take a combination of dimension , against which you want to find the stock
inventDim.InventLocationId = "HYD";

//Set the flag for the selected dimensions as active.
inventDimParm.initFromInventDim(inventDim);

//initialize the inventonhand with item,dimension and dim paramter

inventOnHand.parmItemId(itemid);
inventOnHand.parmInventDim(inventDim);
inventOnHand.parmInventDimParm(inventDimParm);

// Retrieve the onhand info
info(strfmt("Available Physical: %1",
inventOnhand.availPhysical()));
info(strfmt("On order: %1",inventOnhand.onOrder()));

}



To find out stock in inventsum using code X++:
static void ItemOnhandSum(Args _args) {     InventSum           inventsum;     Qty                 availableQty = 0;     ;
    select sum(PostedQty),         sum(Received),         sum(De…

Some Important date functions in AX

Dayname: Retrieves the name of the day of the week specified by a number. wkofyr : Calculates the week of the year in which a date falls
mthofyr: Retrieves the number of the month in the year for the specified date.
mthname : Retrieves the name of the specified month
mkdate : Creates a date based on three integers, which indicate the day, month, and year, respectively.
dayofmth: Retrieves the day of the specified date.
dayofyr: Retrieves the day of the specified date.
year: Get year from date
dayofwk: Calculates the day of the week for a date.
prevmth:  Retrieves the date in the previous month that corresponds most closely to the specified date.
prevyr: Retrieves the date in the previous year that corresponds most closely to the specified date.
prevqtr: Retrieves the date in the previous quarter that corresponds most closely to the specified date.
Today: Retrieves the current date on the system.