Hii,
I am very beginner for Dynamics Ax 2012 and I had created a service for Dynamics AX 2012 R3, use it in my C# program to create a voucher. I am passing the following details in my service method:-
ServiceClient client = new ServiceClient();
CallContext context = new CallContext();
string vendorId = "US-101";
string invoiceNo = "905896875";
string GLCode = "600150";
decimal invoiceAmount = 25000;
decimal discAmount = 250;
Voucher obj = new Voucher();
obj.createVoucher(client, context, vendorId, invoiceNo, invoiceAmount, TransactionDate, GLCode, DueDate, "CAD", discAmount, DiscountDate);
but getting an error "Transaction amount and cash discount must have same sign."
-->Discount is 2%D10
X++ Create Voucher Method
[SysEntryPointAttribute(true)]
public ITECHAPContract createVoucher(VendAccount _vendorId,InvoiceId _invoiceId,Amount _invoiceAmount,TransDate _invoiceDate,LedgerAccount _GLCode,DueDate _dueDate,CurrencyCode _currencycode,DiscAmount _discAmount,DiscDate _discDate)
{
LedgerJournalCheckPost jourCheckPost;
LedgerJournalTable jourTable;
LedgerJournalTrans journalTrans;
DimensionAttributeValueCombination davc;
container offsetDim;
VendTable vendTable = VendTable::find(_vendorId);
LedgerAccount ledgerAccount = _GLCode;
InvoiceId invoiceId = _invoiceId;
TransDate invoiceDate = _invoiceDate;
Amount invoiceAmount = _invoiceAmount;
DueDate duedate = _dueDate;
CurrencyCode currencycode = _currencycode;
DiscAmount discAmount = _discAmount;
DiscDate discDate = _discDate;
ITECHAPContract obj = new ITECHAPContract();
AxLedgerJournalTable header = new AxLedgerJournalTable();
AxLedgerJournalTrans trans = new AxLedgerJournalTrans();
LedgerJournalNameId ledgerJournalNameId = "APInvoice";
LedgerJournalACType accType = LedgerJournalACType::Vend;
LedgerJournalACType offsetAccType = LedgerJournalACType::Ledger;
try
{
header.parmJournalName(ledgerJournalNameId);
header.parmJournalType(LedgerJournalType::VendInvoiceRegister);
header.save();
trans.parmJournalNum(header.ledgerJournalTable().JournalNum);
trans.parmApproved(NoYes::Yes);
trans.parmApprover(HcmWorker::userId2Worker(curuserid()));
trans.parmAmountCurCredit(invoiceAmount);
trans.parmInvoice(invoiceId);
trans.parmTransDate(invoiceDate);
trans.parmDue(duedate);
trans.parmCurrencyCode(currencycode);
trans.parmCashDiscAmount(discAmount);
trans.parmCashDiscBaseDate(discDate);
trans.parmTransactionType(LedgerTransType::Vend);
trans.parmAccountType(accType);
select firstonly RecId from davc where davc.DisplayValue == vendTable.AccountNum;
trans.parmLedgerDimension(davc.RecId);
offsetDim = [ledgerAccount, ledgerAccount,0];
trans.parmOffsetLedgerDimension(AxdDimensionUtil::getLedgerAccountId(offsetDim));
trans.parmOffsetAccountType(offsetAccType);
trans.save();
jourTable = header.ledgerJournalTable();
journalTrans = trans.ledgerJournalTrans();
if (jourTable.RecId > 0)
{
jourCheckPost = ledgerJournalCheckPost::newLedgerJournalTable(jourTable,NoYes::Yes,NoYes::Yes);
{
jourCheckPost.run();
obj.parmReturnCode(1);
obj.parmReturnMessage(strFmt("Voucher: %1 posted successfuly",trans.parmVoucher()));
obj.parmVoucher(trans.parmVoucher());
}
}
}
catch (Exception::Error)
{
obj.parmReturnCode(0);
obj.parmReturnMessage("Error occured in voucher posting");
}
catch (Exception::Warning)
{
info("Warninig");
}
return obj;
}
Thanks,
Deshdeepak