Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics NAV (Archived)

if codeunit.run, Try function, asserterror and associates

Posted on by 566

Hi, an external system is writing in a customized table in dynamics NAV (2018) (called interface table) which I process and then write an item-journal line and then post it.

I am validating the value of the fields in that interface table using try functions and in case of error I mark the record as error so the external system can retrieve it and eventually correct the error shown (for instance: Item code field is empty). This all works fine, but the problem comes when I try to post the line. I have found no way of catching eventual posting errors in order avoid an standard error message for posting (for instance: Not enough stock of product xxxx)

How can I catch the error before it raises? Try function wont work since the procedure writes into the database. "IF codeunit.run Item Jnl.-Post Line" is not allowed for similar reasons...

I have check the preview posting for sales header, but it is kind of tricky since the preview flag is all around codeunit 80 and this is not happening with 22 Item Jnl.-Post Line where I need it.

Any ideas?

*This post is locked for comments

  • AntonioTorre Profile Picture
    AntonioTorre 566 on at
    RE: if codeunit.run, Try function, asserterror and associates

    Great Rehan, that was exactly my problem: future lines of item posting journal could get stuck if i had no means to mark that single line as error.

    I wish Microsoft could give as another approach, but your answer helps a lot.

  • Verified answer
    Rehan Satti Profile Picture
    Rehan Satti 634 on at
    RE: if codeunit.run, Try function, asserterror and associates

    Hi Astur,

    I am creating shipment and posting Sales Order from the web-service exposed methods. I did not give thought to Preview Posting It may not work in my case , because I want to minimize(skip) the errors. and want to skip those order which has errors. For example If an sales order Bin code is missing. Nav can not post that Sales Order due to missing bin code in sales order line. workaround, I am skipping that specific Order. So the end User can fix bin code error. And web service can fetch those order in next cycle and from there on wards Sales order can be posted.

  • AntonioTorre Profile Picture
    AntonioTorre 566 on at
    RE: if codeunit.run, Try function, asserterror and associates

    Thank you Rehan... I was hoping not to have to do that, since there can be lots of potential errors to deal with. About your we-order NAV, standard "Preview" posting is not working for you?

  • Suggested answer
    Rehan Satti Profile Picture
    Rehan Satti 634 on at
    RE: if codeunit.run, Try function, asserterror and associates

    Hi Astur lano,

    Most probably you have exposed a web service which writes data in to the intermediate table. And from there you are posting the line. You can not use try function. I mean the NAV standard posting errors are unavoidable. However you can place various checks methods before posting the line. For example an item has not sufficient quantity for posting. If you can declare a method which ensure that your item has sufficient quantity for posting and return true in case of successful check and false in case of check failed.

    Nutshell is You have to implement check & code logic intelligence  for common posting error. If your line is validate against those check Only then post. Other wise send the error back.

    This is how I am dealing with the web-Order in NAV.

    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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans