Friday, August 6, 2010

How To Cache A object Globally in Ax

There are three way to cache objects.

A global cache is an instance of class - SysGlobalCache, which is nothing but a Map containing Maps with a Key. These Maps contain the actual value and a key.
In Ax, we have three Global Cache Classes

1.Infolog.globalCache()

2.Appl.globalCache()

3. ClassFactory.GlobalCache().

How to use:

static void GlobalCacheSetAndGet(Args _args)
{
SysGlobalCache globalCache;
class test;
;

globalCache = infolog.globalCache();

if (globalCache.isSet(classstr(test), 0))
{
test= globalCache.get(classstr(Test), 0);
return test;
}
else
{
test= new test();
globalCache.set(classstr(Test), 0, test);
return test;
}

}

Sunday, July 25, 2010

Setting max buffer size in Ax2009 for AIF

In Dynamics AX 2009 it can happen that a lengthy operation terminates with the following error message in the InfoLog:
Error executing code: Insufficient memory to run script.
A typical example that can result in this error message is when you are running the Reverse Engineering Tool of Dynamics AX 4.0 SP1. Another very common situation is when you are trying to process very large AIF messages with several thousand lines within AX or within an application that uses the Business Connector like the AX BizTalk Adapter.
With Dynamics AX 4.0 a new mechanism was introduced to limit the maximum amount of memory that can be allocated by variables (in X++ code) in a session. This maximum amount is set to 10 MB by default. For some operations like large AIF messages (that are stored in memory during processing) this is however not enough and so the operation is terminated when the maximum amount is reached.
The second part of the error message "Insufficient memory to run script." clearly indicates that this buffer was reached. It is possible to increase the buffer size in the windows registry by changing the following registery enteries


Key name: [HKEY_CURRENT_USER\Software\Microsoft\Dynamics\5.0\Configuration\(configuration name)] Value name: maxbuffersize Value type: REG_SZ Value: (Maximum amount of memory in MB or 0 for no limit)
For Dynamics AOS it is the following registry key Key name: [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Dynamics Server\5.0\(AOS instance)] Value name: maxbuffersize Value type: REG_SZ Value: (Maximum amount of memory in MB or 0 for no limit)
 This registry entry does, by default, not exist.
 It is recommended not to use value ‘0’ for ‘no limit’.
 After making changes to this registry value, ensure that the Dynamics service and/or client is restarted.

Thursday, July 1, 2010

HOW To Do Debugging In AIF

IF we want to do debugging in AIF then follow the following steps.This is for Inbound processing

1.Go to AOT->Classes->AIFInBoundProcessingService
2.Go to method runAsWrapper
3.Comment the following lines in method

// BP deviation documented
// runas(axaptaUserId,
// classnum(AifInboundProcessingService),
// staticmethodstr(AifInboundProcessingService, processAsUser),
// messageIdContainer);


and replace this with the following line

AifInboundProcessingService::processAsUser(messageIdContainer);

4. Make the processAsUser method public from private

public static void runAsWrapper(AifWindowsUser runAsUserId, container messageIdContainer)
{
AifGatewayQueue gatewayQueue;
userId axaptaUserId;
AifMessageId messageId;
int messageIdContainerIdx = 1;
AifMessage errorMessage;
AifInfoLog aifInfoLog;
SysExceptionLog exceptionLog;
;
aifInfoLog = new AifInfoLog();
try
{
// Convert to Axapta UserId
axaptaUserId = AifEndpointUser::getAxaptaUser(runAsUserId).Id;
new RunAsPermission(axaptaUserId).assert();
// BP deviation documented
// runas(axaptaUserId,
// classnum(AifInboundProcessingService),
// staticmethodstr(AifInboundProcessingService, processAsUser),
// messageIdContainer);
AifInboundProcessingService::processAsUser(messageIdContainer);
CodeAccessPermission::revertAssert();

How To Restore Data In AIFSchemaStore Table

AIFSchemaStore table contains the schema information for all the AIF services in AX

If data is deleted from this table or it doesn't contain the proper schema information then we can not configure endpoint action policy

Steps to regenerate data in AIFSchemaStore table:

1.Delete all data from AIFSchemaStore table
2.Delete all the data from AIFDocumentSchema table
3.Click on refresh button on Services form it will regenerate all the data in AIF SchemaStoretable and documentSchema table
4.To verify after refreshing the services check if In AIFAction table all the actions for services is pointing to the classid of corresponding service class.

Sunday, June 13, 2010

How To Delete All Transaction Data In Ax

If we want to delete only transaction data in Ax .Then it is very simple

Follow these steps

1.Aot->Classes->SysDatabaseTransDelete
2.Run this class it will delete all the transaction data.

Friday, April 16, 2010

How to run AIF job

static void ProcessAIF(Args _args)
{
;

new AifGatewayReceiveService().run();
new AifInboundProcessingService().run();

sleep(100);

new AifOutboundProcessingService().run();
new AifGatewaySendService().run();
}

Saturday, April 10, 2010

Run AIF Without Active Directory

On a local system where there is no network you can RUN AIF. But you need to make slight changes to AIFUtil class. This class queries the domain server (Active directory) to retrieve the user SID …

In no network, the domain server is not available. So it can never query domain server. To avoid this do following:

1. Open AOT (icon in toolbar of ax client)
2. Expand classes treenode
3. Search for AIFUtil
4. Double click on this class and search for the method (left panel) with the name 'getWindowsUserSID'
5. At the bottom there is an assignment to userSid:
userSid = util.GetUserSid(domain, alias);
6. This code must be commented like this:
// userSid = util.GetUserSid(domain, alias);
7. And be replaced with the SID of your user that you are using to import documents into AX. How can you find out the SID of your user? That you can find in the AX database -> table 'dbo.userinfo'. There is a field which contains a SID. Copy the value of that field to the new code line in AIF util class as below:
userSid = 'S-1-5-21-1230085639-4049897806-2686723225-1141';
8. Compile the aifUtil class
9. Unplug your network

Restart AX service and try