Tag Archives: X++

AX 2012: Post Sales Invoice using X++

AX 2012: Post Sales Invoice using X++

static void postSalesInvoice(Args _args)
{
SalesFormLetter salesFormLetter;
SalesTable salesTable;
SalesId salesId = ‘005063’;
System.Exception error;
str strError;
CustInvoiceJour custInvoiceJour;
;

ttsBegin;
try
{
salesTable = SalesTable::find(salesId);

if (salesTable && salesTable.SalesStatus == SalesStatus::Delivered)
{
salesFormLetter = SalesFormLetter::construct(DocumentStatus::Invoice);
salesFormLetter.update(salesTable, systemDateGet(), SalesUpdate::All, AccountOrder::None, NoYes::No, NoYes::No, NoYes::No, NoYes::Yes);

if (salesFormLetter.parmJournalRecord().TableId == tableNum(CustInvoiceJour))
{
custInvoiceJour = salesFormLetter.parmJournalRecord();
info(strFmt(‘Sales Order #:%1 has been successfully posted and Invoice #:%2 is created!’, custInvoiceJour.SalesId, custInvoiceJour.InvoiceId));
}

}
else
{
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 post, please try again!’, salesId));
}
ttscommit;
}

Advertisements

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)
{
#File

Filename fPath;
Filename fName;
Filename fType;

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

#define.sourcePath(sourcePath)
#define.destinationPath(DestinationPath)

[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)
{
#File
Set permissionSet;
Filename fPath;
Filename fName;
Filename fType;

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

#define.sourcePath(sourcePath);
#define.destinationPath(DestinationPath)

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

CodeAccessPermission::assertMultiple(permissionSet);

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

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

CodeAccessPermission::revertAssert();

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

AX 2012: Read CSV File using X++

public void readCsvFile(){
#File
Io io;
container recordCon;
boolean firstLine = true;

FilePath processfilePath = @’C:\Temp\test.csv’;

io = new CommaTextIo(processfilePath, #IO_Read);

if(!io || io.status() != IO_Status::Ok){
throw error(“@SYS19358”);}

while (io.status() == IO_Status::Ok){
recordCon = io.read();
if (recordCon){
if (firstLine){
firstLine = false;} // To skip headeror the firstline
else{
// Do something here…}}}}

AX 2012: Posting Packing Slip using X++

static void JobPostPackingSlip(Args _args)
{
SalesFormLetter_PackingSlip     salesFormLetter_PackingSlip;

SalesTable                      salesTable;
CustPackingSlipJour             custPackingSlipJour;

;

ttsBegin;
salesTable = SalesTable::find(‘SO00000001’);
salesFormLetter_PackingSlip = SalesFormLetter::construct(DocumentStatus::PackingSlip);
salesFormLetter_PackingSlip.showQueryForm(false);
salesFormLetter_PackingSlip.update(salesTable,
systemDateGet(),
SalesUpdate::DeliverNow,
AccountOrder::None,
false,
false);
ttsCommit;

if (CustPackingSlipJour::exist(‘SO00000001’))
info(strFmt(‘Sales Order successfully delivered!’));
else
info(strFmt(‘Sales Order failed to deliver!’));
}