AX 2012, Calling Webservice, Development, Rest APIs, Uncategorized

Calling Rest API from AX 2012

AX 2012 supports system.Net namespace interface. This interface provides simple programming interface for many of the protocols used on the networks today. Herewith i am sharing a simple example to call a rest API asynchronously.  it is very lightweight and has hardly an impact if you are calling asynchronously.

 

static void CallRestAPISample(Args _args)
{
 System.Net.WebHeaderCollection headers ;
 System.Net.WebClient webclient;
 System.Uri uri;
 
 // Create XML msg or string message as parameter to call the Rest API. 
 str msgstring = '<?xml version="1.0"?> ';
 
 msgstring += '<LogRequest>' ;
 
 msgstring += '<ApplicationName>AX Error Tracking</ApplicationName>';
 msgstring += ' <Date>06-22-2017 12:58:22 PM</Date>';
 msgstring += '<ThreadID>0</ThreadID>';
 msgstring += '<LogLevel> <INFO>false</INFO> <DEBUG>false</DEBUG> <ERROR>true</ERROR> <FATAL>false</FATAL> <WARN>false</WARN> </LogLevel>';
 msgstring += '<LogDetails> <ExceptionMessage>Test Exception</ExceptionMessage> <Message>This is test message from AX Logging Call.</Message> </LogDetails> ';
 msgstring += '<Metadata> <Data> <Name>ENV</Name> <Value>DEV</Value> </Data> <Data> <Name>Server</Name> <Value>AX AOS 1</Value> </Data> <Data> <Name>Source</Name> <Value>DAX</Value> </Data> </Metadata>';
 msgstring += '<Email> <From>FromAddr@Fromserver.com</From> <To>toaddrr@toserver.com</To> <Subject>AX Logging Test</Subject> <Message>This is test message</Message> <HasAttachments>false</HasAttachments> <IsBodyHtml>true</IsBodyHtml> <IncludeLogDetails>true</IncludeLogDetails> </Email>';
 msgstring += '</LogRequest>';
 
 
 info(strFmt("%1",time2str(timeNow(),1,1)));
 // initilizing host URI
 uri = new System.Uri("http://LogginServiceHost/api/Log/LogRequest");// FAKE SERVICE HOST ADDRESS
 // initializing webClient
 webclient = new System.Net.WebClient();
 headers = webclient.get_Headers();
 // Set header content type
 Headers.Add(System.Net.HttpRequestHeader::ContentType, "text/xml;charset=utf-8");
 // call API asynchronously
 webclient.UploadStringAsync(uri,msgstring);
 
 info(strFmt("%1",time2str(timeNow(),1,1)));

}

Advertisements
Standard
Uncategorized

Management Reporter 2012 – AX 2012 R3 – Error creating building block

There is a system exception  System.InvalidOperationException when POSTINGTYPE column in the MAINACCOUNT table of the MicrosoftDynamicsAX database, not matching “LedgerPostingType” baseEnum in the AOT.

If you do find a mismatch, you will need to re-create the DataMart after fixing it.  Here are the steps to re-create the DataMart:

 

A. Close all instances of MR and back up the MR database.

B. Start the Configuration Console and click on the integration under ERP Integrations.

C. Click the Disable Integration button and wait a moment for that to take effect.

D. Click the Remove link in the top-right.

E. Stop the MR services at the top level of the Configuration Console and then delete the DDM database from SQL.

F. In the Configuration Console, start the MR services and then click File -> Configure and deploy a new DDM integration.

G. Enable the integration and wait for the initial load to complete. It will be complete when the second line from the top changes to a date/time stamp.

Standard
AX 2009, AX 2012, Development, Dynamics AX, Uncategorized

How to send a file to the printer in dynamics AX

How to send a file to the printer in dynamics AX

Following Job demonstrates on how to send a file from the file system to the locally connected printer( printer physically can be network or local but it should be added to the client and its name should be visible in the control panel–> devices and printers)

static void sendToPrinter(Args _args)
{
PrintJobSettings printJobSettings = new PrintJobSettings();
Dialog dialog = new Dialog();
DialogField dialogFileName;
str CoreLabelExe;
str CoreLabelParm;
;
// initiallize printer with the printer name. This initiallization automatically
// gets dll file details and port details.
printJobSettings = new PrintJobSettings();
printJobSettings.SetTarget(PrintMedium::Printer);
printJobSettings.deviceName(‘Microsoft XPS Document Writer’);
dialogFilename = dialog.addField(typeid(FilenameOpen));
if (dialog.run())
{
// finding executable DLL
CoreLabelExe = WinAPI::findExecutable(dialogFileName.value());
// Create Shell command parameter
CoreLabelParm = strFmt(‘ /PT “%1” “%2” “%3” “%4″‘,
dialogFileName.value(),
printJobSettings.printerPrinterName(),
printJobSettings.printerDriverName(),
printJobSettings.printerPortName());
// run dll on the shel with parameter
winAPI::shellExecute(CoreLabelExe, CoreLabelParm);
}
}

Standard
AX 2012, Uncategorized, What is new

Dynamics AX 2012 R2 has got an excellent feature, ‘Data Partitions”. It enables Business data isolation but sharing the same business application.

Benefits

  • If an organization runs multiple business entities that shares the same business application, can Share IT infrastructure across independent businesses.
  • While sharing the IT infra, Organization achieves strict data isolation across businesses.
  • This reduces Total cost of ownership (TCO) for managing IT infrastructure.

Data partition basics

Below are some basic features of data partitions. The implementor should understand these before designing/preparing for data partitions.

Understanding Partion and Legal entitiy

Understanding Partition and Legal entity

  • Metadata (Business application)  is common across all partitions.
  • Enabling/disabling configuration key affects all partitions.
  • Named user licenses are calculated per principal, i.e. AD user, regardless of the number of partitions they have access to.
  • A default partition named Initial is always created for each AX instance.
  • DAT company exists in every partition. It is automatically created when a new partition is created.
  • A company with same name can exist in multiple partitions. Intercompany doesn’t work across partitions
  • AX users are defined per partition.
    • With in a partition a principal can be associated with one AX user.
    • Each user has a “default” partition associated with them, however a user can be authorized to access data in more than one partition.
    • AX user IDs other than admin and Guest are unique across partitions.
    • The principal that creates a new partition automatically becomes the admin user in the partition
    • Each partition contains at least one company or legal entity. A legal entity occurs in only one partition. When you create a legal entity, the system assigns it to the current partition. The legal entity can never be moved to another partition. However, its data can be exported from the partition and then imported to another company in another partition.
    Data Partition Structure

    Data Partition Structure

    • User to role assignment is per partition.
    • Organizations (e.g. departments, cost centers, etc.)  and hierarchies are defined within a partition.

    Data Abstraction Levels

    • User-Role-Organization assignment is per-partition.
    • Intended partition is specified at session creation time via client configuration.
    • If no partition is specified then the user’s default partition is chosen
  •  In a partitioned system, Services and Application Integration Framework (AIF) is a shared subsystem. To guarantee that incoming requests are correctly isolated, you can restrict an inbound integration port to a particular partition. Additionally, you can specify a target partition for an incoming request by including the partition key in an XML element in the header of the document. Similarly, outbound responses indicate the source partition for the response data by including the partition key in the header.   Because AIF uses a single gateway queue, a system administrator can view all documents in the queue, AIF history, or exceptions list in any partition. The forms that display these lists now have a field that shows the partition key for each document. for more info click
  • Like AIF, the batch processing framework is a shared subsystem. One batch server is shared across partitions. However, each batch job is associated with a specific partition. The batch server executes batch jobs in the context of the correct partition. To view batch jobs or their history, you must log on to the partition that the batch jobs are associated with.
  • Separate organizational hierarchies – Each partition contains its own organizational hierarchy, which includes one or more legal entities. Like a new deployment of Microsoft Dynamics AX, each partition that is created contains the DAT company as a default legal entity. System administrators can add legal entities to each partition. Legal entities are never shared between partitions, even if the legal entities have the same name.

Data partitioning architecture

Datapartition architecture

Recommendation

Implementation choice must be made carefully as the companies between two partitions cannot be merged and Intercompany features cannot be used. The only option is to use Data migration tool kit for data export import between partitions and AIF for inter company operations.

How it is implemented Technically?

  1. A partition Table is introduced. that keeps the list of partitions in the system.
  2. The partition key  is applied in all contexts as data area id used to apply, like all queries, forms etc.
  3. Every table in the system now has one more field named partition, that is nothing but the record id of the record created in the step one.
  4. Partition table implementation
  5. Cross company query doesn’t work across paritions
  6. Global function getcurrentpartitionrecid() introduced.

References

  1. What’s New: Data partitioning [AX 2012]
  2. Partitions, Companies, and Data Isolation in Microsoft Dynamics AX [AX 2012]

Dynamics AX 2012 R2 Data Partitioning

Aside
AX 2012, Development, Dynamics AX, Uncategorized

Reserve quantity by X++ code

Quick code snippet to reserve the quantity by X++

SalesLine locSalesline;

InventMovement inventmovement;

InventUpd_Reservation reservation;

inventMovement = InventMovement::constructNoThrow(locSalesline,InventMovSubType::None);

reservation = InventUpd_Reservation::newinventdim(inventMovement, InventDim::find(InventDimReserveFrom),-1*inventqty, false);

reservation.updateNow();

Standard