code unit 80 (sales Post)

arindamarindam Member Posts: 176
Hi All,

I am having a problem on calling a Navision code unit. The senario:

I have a button called 'POST". My objective is that when user will click the post button his selected (selction of a Sales Order Header Id is done) of an Order or Invoice, will get posted.

I want to call the codeunit 80/81 from my code. How shall I call code unit 80 from my code ?

Thanks in advance. Please help.

Arindam

Answers

  • nunomaianunomaia Member Posts: 1,153
    Declare SalesPost has codeunit of type Sales-Post

    In code
    SalesPost.RUN(SalesHeader);

    Other way around, in menu item define runobject has Codeunit Sales-Post
    Nuno Maia

    Freelance Dynamics AX
    Blog : http://axnmaia.wordpress.com/
  • krikikriki Member, Moderator Posts: 9,110
    or also :
    CODEUNIT.RUN(CODEUNIT::"Sales-Post",SalesHeader);
    
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • arindamarindam Member Posts: 176
    Thank you very much for your help. It solved my problem.

    Now I want to know to post a Sales Order what code unit shall I use ? Also to post an Invoice what code unit shall I use ?

    Once again thanks in advance.
  • David_CoxDavid_Cox Member Posts: 509
    arindam wrote:
    Thank you very much for your help. It solved my problem.

    Now I want to know to post a Sales Order what code unit shall I use ? Also to post an Invoice what code unit shall I use ?

    Once again thanks in advance.

    They all use the same codeunit as they are all the same table! :D
    Analyst Developer with over 17 years Navision, Contract Status - Busy
    Mobile: +44(0)7854 842801
    Email: david.cox@adeptris.com
    Twitter: https://twitter.com/Adeptris
    Website: http://www.adeptris.com
  • diptish.naskardiptish.naskar Member Posts: 360
    arindam wrote:
    Thank you very much for your help. It solved my problem.

    Now I want to know to post a Sales Order what code unit shall I use ? Also to post an Invoice what code unit shall I use ?

    Once again thanks in advance.

    Don't get confused for the Document Type....as David said...its the same SALESHEADER. :)
    Diptish Naskar
    For any queries you can also visit my blog site: http://msnavarena.blogspot.com/
  • arindamarindam Member Posts: 176
    Thanks Diptesh.

    Now if i just want to post only 2 Order then how come I make the code unit understand that it should perform the posting task for these 2 Orders only ? say I marked 2 of the Orders.

    I hope I am able to clear my point.

    Arindam
  • DenSterDenSter Member Posts: 8,305
    General tip:
    If you want to automate anything in NAV that is available in the standard database, you turn on the debugger and see how it's done in standard NAV. Learn from that and apply that knowledge to your project.

    So in this instance, you want to automate posting an invoice in a button. What you do is create an invoice, turn on the debugger, and post it. See what happens under the hood and program it in your button.
  • kinekine Member Posts: 12,562
    Just one hint for you: "loop".
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • MbadMbad Member Posts: 344
    Easiest way would probably be to check how the mass-posting reports work.
  • arindamarindam Member Posts: 176
    Once again thanks for your tips.

    Looping is happening perfectly. My code is :

    Repeat
    if mark then
    CODEUNIT.RUN(CODEUNIT::"Sales-Post",recSalesOrderHead);
    until (..)

    recSalesOrderHead is the record object for Sales Header.
    My problem is whenever i am passing this it is taking the fisrt record which is 'offer' in this case. I want to pass all the marked order to be posted.

    Please help
  • kinekine Member Posts: 12,562
    and where you have "reading" of the record? Something like recSalesOrderHead.GET, or recSalesOrderHead.FINDxxx etc...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • arindamarindam Member Posts: 176
    I am using

    recSalesOrderHead.SETRANGE(recSalesOrderHead."No.","No.");
    CODEUNIT.RUN(CODEUNIT::"Sales-Post (Yes/No)",recSalesOrderHead);

    Here I am trying to set the sales order number i want to pass to the code unit.

    But when I am nevigating the code unit in debug mode it is showing that no record is selected at the code unit level and throwing an error.

    If I can pass my desired Sales Header "No." to the code unit then I think it will solve my problem. But I am not able to do that.

    Please advice.
  • diptish.naskardiptish.naskar Member Posts: 360
    Hi Arindam,

    I was going through the posts..well what Kine said is right...LOOP will do. Try using find('-') or FINDFIRST after the setrange that you have applied.
    Diptish Naskar
    For any queries you can also visit my blog site: http://msnavarena.blogspot.com/
  • arindamarindam Member Posts: 176
    Thanks Diptish and all who answers my query.

    It solved. I use -

    recSalesOrderHead.SETRANGE(recSalesOrderHead."No.","No.");
    recSalesOrderHead.FIND('-');
    CODEUNIT.RUN(CODEUNIT::"Sales-Post",recSalesOrderHead);

    It is now passing the current record to the code unit.

    Thank you guys. You solved this problem.

    Regards,
    Arindam
Sign In or Register to comment.