Category Archives: X++

AX 2012: Convert Base64String to Images File

Convert Base64String to Images files or PNG Files.

In my scenario, I need to read Base64String from other application through web services and save it as images file in my server computer.


static void convertBase64ToImages(Args _args)


str base64String = ‘XXXXXX-BASE64STIRNG-XXXXXX’;

// Save the image

AifUtil::saveBase64ToFile(@”C:\TEMP\TEST1.PNG”, base64String);



AX 2012: Post Packing Slip using X++

AX 2012: Post Packing Slip using X++

static void postPackingSlip(Args _args)
SalesFormLetter salesFormLetter;
SalesTable salesTable;
SalesId salesId = ‘SO00001’;
System.Exception error;
str strError;
CustPackingSlipJour custPackingSlipJour;

salesTable = SalesTable::find(salesId);

if (salesTable && salesTable.SalesStatus == SalesStatus::Backorder)
salesFormLetter = SalesFormLetter::construct(DocumentStatus::PackingSlip);
salesFormLetter.update(salesTable, systemDateGet(), SalesUpdate::PackingSlip, AccountOrder::None, NoYes::No, NoYes::No, NoYes::No);

if (salesFormLetter.parmJournalRecord().TableId == tableNum(custPackingSlipJour))
custPackingSlipJour = salesFormLetter.parmJournalRecord();
info(strFmt(‘New Packing Slip #:%1 successfully created for Sales Order #:%2’, custPackingSlipJour.PackingSlipId, custPackingSlipJour.SalesId));
info(strFmt(‘%1 does not exsists or null in the system, please try again!’, salesId));

catch (Exception::CLRError)
error = CLRInterop::getLastException();
strError = error.ToString();

info(strfmt(‘%1’, strError));
info(strFmt(‘%1 failed to delivered, please try again!’, salesId));

AX 2012 R3: Convert Images (JPEG) to Base64

How to convert images to base 64

public str (RefRecId _refRecId, RefTableId _refTableId)

System.Drawing.Image image;
System.IO.MemoryStream memoryStream;
str filePath = ”;
Filename fileName = ”;
DocuRef docuRef;

select docuRef
where docuRef.RefRecId == _refRecId
&& docuRef.RefTableId == _refTableId;

if (docuRef)

// Get Images complete File Name
fileName = docuRef.completeFilename();

image = System.Drawing.Image::FromFile(@Filename);
memoryStream = new System.IO.MemoryStream();
image.Save(memoryStream, System.Drawing.Imaging.ImageFormat::get_Jpeg());
filePath = System.Convert::ToBase64String(memoryStream.ToArray());

return filePath;

Screen Shot:




Assuming parameters _refRecId and _refTableId came from InventTable where the Product Images is set in Released Product under Product Image function. See image below:



AX 2012: Client found response content type of “, but expected ‘text/xml’. The request failed with an empty response.

Error while calling SSRS  Reports in AX 2012

Error Details:

Client found response content type of “, but expected ‘text\xml’. The request failed with an empty response.

The attempt to connect to the report server failed. Check your connection information and that the report server is a compatible version.

Error Screen Shots:

Client found response content type of


Solution (Based on my experiences):

  1. Check your Reporting Server, check local drive where your Reporting Server Files are stored. Check if there still available spaces.
  2. In my case, Client found response content type of (sol)
  3. After I cleaned my Local Disk (C:), error is resolved.

AX 2012: Get Exchange Rates


Get Exchange Rates in AX 2012

Parameters are CurrencyCode and TransDate.


public ExchRate getExchRateFind(CurrencyCode _currencyCode = ”, TransDate _transDate = systemDateGet())
ExchangeRateType ExchangeRateType;
ExchangeRateCurrencyPair ExchangeRateCurrencyPair;
ExchangeRateHelper exchangeRateHelper;
CurrencyExchangeRate exchangeRate1;
CurrencyExchangeRate exchangeRate;

exchangeRateHelper = ExchangeRateHelper::newExchangeDate(Ledger::current(), _currencyCode, _transDate);
exchangeRate1 = exchangeRateHelper.getExchangeRate1();
exchangeRate = exchangeRateHelper.displayStoredExchangeRate(exchangeRate1);

return exchangeRate;

AX 2012: Move file to another folder using WinAPI

static void ArisMoveFileUsingWinAPI(Args _args)

Filename fPath;
Filename fName;
Filename fType;

FileName DestinationPath = @’D:\DestinationFolder\’;
FileName sourcePath = @’D:\SourceFolder\test.csv’;;


[fPath, fName, fType] = fileNameSplit(#sourcePath);

WinAPI::moveFile(#sourcePath, strFmt(‘%1%2%3’, #destinationPath, fName, fType));

Box::info(‘File\s moved successfully!’);

AX 2012: Moving File to another Folder using System.IO.File

static void ArisMoveFileUsingSystemIOFile(Args _args)
Set permissionSet;
Filename fPath;
Filename fName;
Filename fType;

Filename sourcePath = @’D:\SourceFolder\test.csv’;
FileName DestinationPath = @’D:\DestinationFolder\’;


permissionSet = new Set(Types::Class);
permissionSet.add(new FileIOPermission(sourcePath,#io_write));
permissionSet.add(new InteropPermission(InteropKind::ClrInterop));


[fPath, fName, fType] = fileNameSplit(sourcePath);

System.IO.File::Move(sourcePath, strFmt(‘%1%2%3’, #destinationPath, fName, fType));


Box::info(‘File\s moved successfully!’);