web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Getting Error while creating voucher:- "Transaction amount and cash discount must have same sign."

(0) ShareShare
ReportReport
Posted on by
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."
transaction-Error.jpg
-->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

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Ludwig Reinhard Profile Picture
    Microsoft Employee on at

    Hi,

    Have you tried entering a negative discount amount?

    Best regards,

    Ludwig

  • Community Member Profile Picture
    on at

    Hi, Ludwig

    Thanks for your immediate response, but I had tried this and getting this error

    cashdiscount.jpg

    Thanks

  • Verified answer
    Ludwig Reinhard Profile Picture
    Microsoft Employee on at

    Hi,

    In your Code I cannot identify the cash Discount Code field.

    You have the discount amount and discount date but the Code seems missing.

    Can you add an existing code that results in the discount amount that you entered?

    Best regards,

    Ludwig

  • Community Member Profile Picture
    on at

    Vendor obj = new Vendor();

    obj.getVendorDetails(client, context, vendorId);

    Method To get Vendor Details 

    public Contract getVendorDetails(VendAccount _vendorId)
    {
    Contract obj = new Contract();

    VendTable vendTable = VendTable::find(_vendorId);

    if (vendTable.RecId)
    {
    obj.parmPaymentTermsId(vendTable.PaymTermId);
    obj.parmcashDisc(vendTable.CashDisc);
    obj.parmCurrency(vendTable.Currency);
    }
    else
    {
    obj.parmReturnCode(0);
    obj.parmReturnMessage("The provided Vendor Id does not exist.");
    }

    return obj;

    }

    C# code to extract details

    if (obj.CashDiscount != string.Empty)
    {
    string[] str = obj.CashDiscount.Split('%');
    discRate = Convert.ToInt32(str[0]);
    discDays = Convert.ToInt32(Regex.Replace(str[1], "[^0-9]+", string.Empty));
    }

    DiscountAmount=(invoiceAmount*discRate)/100;

    Thanks
  • Community Member Profile Picture
    on at

    Hi Dr. Ludwig,

    Thank you so much got your point "cash Discount Code field" now its working fine.

    Thanks

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans