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 NAV (Archived)

"attempted to divide by zero navision" error

(0) ShareShare
ReportReport
Posted on by 1,893

Dear Experts,

I have write the code for calculate the INR value of foreign purchase invoice. But when I try to run the report it is showing the error:

"attempted to divide by zero navision"

My code are below:

Purch. Inv. Line - OnAfterGetRecord()
txtINRValue := txtFinlAmount * 1/(recPurchInvHeader."Currency Factor");

Here txtINRValue,txtINRValue are decimal type variables.

Please help me to resolve it.

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Stefano Demiliani Profile Picture
    37,166 Most Valuable Professional on at

    You’ve to test if recPurchInvHeader."Currency Factor" is 0 before performing the calculation:

    IF recPurchInvHeader."Currency Factor" <> 0 then

    txtINRValue := txtFinlAmount * 1/(recPurchInvHeader."Currency Factor")

    ELSE

    txtINRValue := 0;

  • Verified answer
    Tharanga Chandrasekara Profile Picture
    23,118 on at

    You can use below statement :

    IF recPurchInvHeader."Currency Factor" <> 0 THEN

        txtINRValue := txtFinlAmount * 1/(recPurchInvHeader."Currency Factor")

    ELSE

         txtINRValue := txtFinlAmount;

  • Suggested answer
    manish.yadav Profile Picture
    1,893 on at

    Thank you very much. I have tested it, working fine. You guys are always best.

  • Verified answer
    Olister Rumao Profile Picture
    3,967 on at

    Hi,

    Have you used

    recPurchInvHeader.FINDFIRST or recPurchInvHeader.GET?

    As, the recPurchInvHeader."Currency Factor" results to be zero without FINDFIRST or GET function.

    The  IF recPurchInvHeader."Currency Factor" <> 0

    might only check if there is any value in recPurchInvHeader."Currency Factor" but using GET or FINDFIRST might give the actual value. Try putting MESSAGE to check what values you get.

  • manish.yadav Profile Picture
    1,893 on at

    Hello Olister,

    I have tried with

    IF recPurchInvHeader.GET(recPurchInvHeader."Currency Factor") THEN BEGIN

    IF recPurchInvHeader."Currency Factor" <> 0 THEN

      txtINRValue := txtFinlAmount * 1/(recPurchInvHeader."Currency Factor")

    ELSE

      txtINRValue := txtFinlAmount;

    END;

    but result is showing 0 value in all column. What should I do? Please suggest me.

  • Suggested answer
    Stefano Demiliani Profile Picture
    37,166 Most Valuable Professional on at

    Currrncy Factor must be different than 0 in your Purchase Invoice Header. Check your Currency Code you’re using, you’re not using your local base currency so a conversion factor must be set. Otherwise you obtain zero always.

  • manish.yadav Profile Picture
    1,893 on at

    Dear Stefano,

    Thank you for your valuable feedback and sharing the knowledge.

    Currently I am using the below code to get the INR value. But I don't know the reason, In some invoices value is coming correctly(converted amount which is matched with detailed vendor ledger entry) and some invoice have coming the invoice amount not coming the converted amount.

    IF recPurchInvHeader."Currency Factor" <> 0 THEN

       txtINRValue := txtFinlAmount * 1/(recPurchInvHeader."Currency Factor")

    ELSE

        txtINRValue := txtFinlAmount;

    I have attached the screenshot below.

    1212.test01.png

  • Suggested answer
    Stefano Demiliani Profile Picture
    37,166 Most Valuable Professional on at

    I suspect that in these cases the Currency Factor in your Purchase Invoice Header is 0.

  • manish.yadav Profile Picture
    1,893 on at

    No, sir in every Purchase Invoice Header  have a value. 0 is not there.

  • manish.yadav Profile Picture
    1,893 on at

    As per Olister, if I added the code in my report, problem is resolved.

    recPurchInvHeader.GET("Document No.");

    thank you very much Olister.

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 NAV (Archived)

#1
HoangNam Profile Picture

HoangNam 7

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans