Wednesday, January 15, 2014

Currency Conversion in Dynamics AX 2012


In Ms Dynamics Ax 2009
static void CurrencyConverter(Args _args)
{
                 CurrencyExchHelper currencyExchangeHelper;
                 AmountMst amountMST;
                 CurrencyCode transCurrency;
                AmountCur amountCur;
         ;
                 amountCur = 5000.00;
                currencyExchangeHelper = CurrencyExchHelper::newExchDate(“KSI”,”USD”,systemDateGet());
                amountMST = currencyExchangeHelper.calculateAmountCurToMst(amountCur ,true);
                info(strFmt(“%1″,amountMST));
}

In Ms Dynamics Ax 2012
static void SR_CEH_Example11(Args _args)
{
CurrencyExchangeHelper currencyExchangeHelper;
CurrencyCode transCurrency = ‘EUR’;
AmountCur amountCur = 500.00;
AmountMst amountMST;

currencyExchangeHelper = CurrencyExchangeHelper::newExchangeDate(Ledger::current(), systemDateGet());
amountMST = currencyExchangeHelper.calculateTransactionToAccounting(transCurrency, amountCur ,true);
info(strFmt(‘%1′,amountMST));
}

Common email errors in AX 2012


When we use the Dynamics AX to send email, sometimes we will run into an CDO.Message issue with error message Method ‘send’ in COM object of class ‘CDO.Message’ returned error code 0×80040211 () which means: .

The error codes listed below are really useful when troubleshooting the issue:

Value Remarks
 0×80040201
Exception %1 was generated at address %2. 0×80040202 No data source has been opened for the object.

0×80040203

The object does not support this type of data source.

0×80040204

The object does not support the requested property name or namespace.

0×80040205

The object does not support the requested property.

0×80040206

The object is not active. It may have been deleted or it may not have been opened.

0×80040207

The object does not support storing persistent state information for objects.

0×80040208

The requested property or feature, while supported, is not available at this time or in this context.

0×80040209
No default drop directory has been configured for this server.

0x8004020A

The SMTP server name is required, and was not found in the configuration source.

0x8004020B

The NNTP server name is required, and was not found in the configuration source.

0x8004020C

At least one recipient is required, but none were found.

0x8004020D

At least one of the From or Sender fields is required, and neither was found.

0x8004020E

The server rejected the sender address. The server response was: %1

0x8004020F

The server rejected one or more recipient addresses. The server response was: %1

0×80040210

The message could not be posted to the NNTP server. The transport error code was %2. The server response was %1

0×80040211

The message could not be sent to the SMTP server. The transport error code was %2. The server response was %1

0×80040212

The transport lost its connection to the server.

0×80040213

The transport failed to connect to the server.

0×80040214

The Subject, From, and Newsgroup fields are all required, and one or more was not found.

0×80040215

The server rejected the logon attempt due to authentication failure. The server response was: %1

0×80040216

The content type was not valid in this context. For example, the root of an MHTML message must be an HTML document.

0×80040217

The transport was unable to log on to the server.

0×80040218

The requested resource could not be found. The server response was: %1.

0×80040219

Access to the requested resource is denied. The server response was: %1.

0x8004021A

The HTTP request failed. The server response was: %1.

0x8004021B

This is a multipart body part. It has no content other than the body parts contained within it.

0x8004021C

Multipart body parts must be encoded as 7bit, 8bit, or binary.

0x8004021E

The requested property was not found.

0×80040220

The “SendUsing” configuration value is invalid.

0×80040221

The “PostUsing” configuration value is invalid.

0×80040222

The pickup directory path is required and was not specified.

0×80040223

One or more messages could not be deleted.

0×80040227

The property is read-only.

0×80040228

The property cannot be deleted.

0×80040229

Data written to the object are inconsistent or invalid.

x8004022A
The requested property is not in the mail header namespace.

0x8004022B

The requested character set is not installed on the computer.

0x8004022C

The ADO stream has not been opened.

0x8004022D

The content properties are missing.

0x8004022E

Content properties XML must be encoded using UTF-8.

0x8004022F

Failed to parse content properties XML.

0×80040230

Failed to convert a property from XML to a requested type.

0×80040231

No directories were specified for resolution.

0×80040232

Failed to resolve against one or more of the specified directories.

0×80040233

Could not find the Sender’s mailbox.

0×80040234

Binding to self is not allowed.

0×80044000

The first argument is invalid.

0×80044001
The second argument is invalid.

0×80044002

The third argument is invalid.

0×80044003

The fourth argument is invalid.

0×80044004

The fifth argument is invalid.

0x800CCE05

The requested body part was not found in this message.

0x800CCE1D

The content encoding type is invalid.

How to get field value from AXgroup in EP



string  var = (string)this.EpDataSourceName.GetDataSet().DataSetViews["DataSourceName"].GetCurrent().GetFieldValue("Fieldname");

Example:
I have get vendor account value from PurchReqCreateDataset
string  vendorID = (string)this.PurchReqCreateDs.GetDataSet.DataSetViews["PurchReqTable"].GetCurrent().GetFieldValue("VendAccount");

Create a alert in AX 2012


void CreateAlert()
{
EventInbox inbox;
BomTable bomTable;
UserGroupList UserGroupList;
;
while select UserGroupList
where UserGroupList.groupId == ‘Admin’
{
inbox.initValue();
inbox.ShowPopup = NoYes::Yes;
inbox.Subject = “Creation of New Record”;
inbox.Message = “A New Item Id–>” + this.ItemId +” was Added by “+curuserid()+ ” under the BOM–>”+ this.BOMId;
inbox.AlertedFor = “BOM-> “+this.BOMId +”,” + curuserid();
inbox.SendEmail = false;

inbox.TypeId = classnum(EventType);
inbox.AlertTableId = tablenum(BOM);
inbox.AlertFieldId = fieldnum(BOM, ItemID);
inbox.TypeTrigger = EventTypeTrigger::RecordInsert;
inbox.CompanyId = curext();
inbox.InboxId = EventInbox::nextEventId();
inbox.ShowPopup = NoYes::Yes;
inbox.AlertCreatedDateTime = DateTimeUtil::getSystemDateTime();
inbox.UserId = UserGroupList.userId;
inbox.insert();
}


}

Custom lookup

public void lookup(FormControl _formControl, str _filterStr)
{
sysTableLookup sysTableLookup;
Query query = New Query();
QueryBuildDataSource qbdsJour, qbdsTrans,qdbsVend;
QueryBuildRange qbr;
;
sysTableLookup = SysTableLookup::newParameters(tableNum(VendPackingSlipJour), _formControl);
qbdsJour = query.addDataSource(tableNum(VendPackingSlipJour));
qbdsTrans = qbdsJour.addDataSource(tableNum(VendPackingSlipTrans));

qbdsJour.relations(true);
qbr = qbdsTrans.addRange(fieldNum(VendPackingSlipTrans, ItemId));
qbr.value(<ItemId>);
qbdsTrans.relations(true);
sysTableLookup.addLookupfield(fieldNum(VendPackingSlipJour, GRNNumber_IN));
sysTableLookup.addLookupfield(fieldNum(VendPackingSlipJour, PurchId));
sysTableLookup.addLookupfield(fieldNum(VendPackingSlipJour, OrderAccount));
sysTableLookup.parmQuery(query);
sysTableLookup.performFormLookup();


}

AX 2012 SSRS report save as PDF


Just came across one of the common requirements of saving AX SSRS report in a specified folder. Here’s is sample code for achieving this requirement:

1. In the controller class, modify the method ‘preRunModifyContract’

public class myCustomReportController extends SrsReportRunController
{
SRSPrintDestinationSettings printDestinationSetting;
}

protected void preRunModifyContract()
{
FolderName      filePath = “C:\\xyz\\Customer Transactions\\”; //You may paramterize this also
;

printDestinationSetting = new SRSPrintDestinationSettings();
printDestinationSetting.printMediumType(SRSPrintMediumType::File);
printDestinationSetting.fileName(
strFmt(“%1%2_%3_%4_%5.pdf”,
filePath,
date2str(systemDateGet(),321,2,0,2,0,2),    //Date
CustTrans.Voucher,         //Voucher
CustTrans.AccountNum,  //Customer
timeNow()));
printDestinationSetting.fileFormat(SRSReportFileFormat::PDF);
printDestinationSetting.overwriteFile(true);
this.parmReportContract().parmPrintSettings(printDestinationSetting);
}


This should override the print job settings for the custom report and will save the pdf file in the desired location. Please note that the client machine will not show the report on screen or print in printer since all the user settings will be overwritten by this code for that specific code.