how to execute Report Automatically (After posting Inv)

bangswitbangswit Member Posts: 265
hi all.... i have create Report 50001
so... how to execute it automatically after i post Sales Invoice to be Posted Sales Invoiced?
thanks

Comments

  • RaniShouraRaniShoura Member Posts: 34
    Hi,

    The post process is happening in code unit 80, 81, 82 depends on the usage scenario ( if you elaborate more , I might could help you more).

    But from my past experience you really don't want to add any more logic or transaction on posting process, try to refine the business process. I'm sure you can do it without going through modifying those units.

    Regards
    Rani Shoura
  • bangswitbangswit Member Posts: 265
    RaniShoura wrote:
    Hi,

    The post process is happening in code unit 80, 81, 82 depends on the usage scenario ( if you elaborate more , I might could help you more).

    But from my past experience you really don't want to add any more logic or transaction on posting process, try to refine the business process. I'm sure you can do it without going through modifying those units.

    Regards

    or maybe we can add in form 43 ??
    add some code here....
    <Control71> - OnPush()
    IF ApprovalMgt.PrePostApprovalCheck(Rec,PurchaseHeader) THEN
      CODEUNIT.RUN(CODEUNIT::"Sales-Post (Yes/No)",Rec);
    

    is that better?
  • RaniShouraRaniShoura Member Posts: 34
    bangswit wrote:
    or maybe we can add in form 43 ??
    add some code here....

    This depends if he is using only invoice form to post invoice (While you know you can post an invoice from a sales order)....

    And I would never recommend any customization from Forms, migration and control is usually hell from there
    Rani Shoura
  • bangswitbangswit Member Posts: 265
    RaniShoura wrote:
    bangswit wrote:
    or maybe we can add in form 43 ??
    add some code here....

    This depends if he is using only invoice form to post invoice (While you know you can post an invoice from a sales order)....

    And I would never recommend any customization from Forms, migration and control is usually hell from there

    owww... i see
    so what do you suggest for me?
  • RaniShouraRaniShoura Member Posts: 34
    What is the use case??
    Rani Shoura
  • bangswitbangswit Member Posts: 265
    RaniShoura wrote:
    What is the use case??

    i want... after posting from sales invoice to be posted sales invoiced
    it execute codeunit no 50001 that I already made
    for export data to be txt file
  • RaniShouraRaniShoura Member Posts: 34
    Option 1

    Please note that this option is not recommended at least by me \:D/
    OK here is where you have to put it in a code unit

    In Code unit 80 - Procedure On run At the bottom of the procedure
    // Your code must go here , but you have to check if Invoice=True
    
    UpdateAnalysisView.UpdateAll(0,TRUE);
    UpdateItemAnalysisView.UpdateAll(0,TRUE);
    Rec := SalesHeader;
    
    Option 2
      1 - Add a bit field to the Sale Header Table And Name it Text Exported Table 36
    [list=2]2 - Add The Same Field with Same Field Number in the Sales invoice Header Table 112[/list]
    [list=3]3 - Have a batch job (Job Queue) that will do what ever you want on the basis of the table 112[/list]
    [list=4]4 - Once your changes are done reset the bit switch[/list]

    Hope this will help
    Rani Shoura
  • BeliasBelias Member Posts: 2,998
    RaniShoura wrote:
    Option 1

    Please note that this option is not recommended at least by me \:D/
    OK here is where you have to put it in a code unit

    In Code unit 80 - Procedure On run At the bottom of the procedure
    // Your code must go here , but you have to check if Invoice=True
    
    UpdateAnalysisView.UpdateAll(0,TRUE);
    UpdateItemAnalysisView.UpdateAll(0,TRUE);
    Rec := SalesHeader;
    
    Option 2
    Not recommened by me, too: you should create the file after the transaction is committed (thus, AFTER the codeunit have been succesfully completed). It's not a safe to add external processing (like creating a text file) during the posting routine...it can cause problems during posting, and you also make the transaction longer (thus increasing the possibility of locks).
    i would go for a separate process that allows you to filter posted sales invoices and create a text file for each of them (something like RaniShoura's second option)
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
  • kash387kash387 Member Posts: 111
    I am not sure but try this one....

    OnPush trigger itself you can try this one....
    // Add one line here
     globalvar (code 10/20) := rec."No.";
     
    // Standard coding..!!
     if approval.... then
     codeunit.run(80,rec);
    
    // Add lines here....!!
     SalesInvHeader.RESET; // SalesInvHeader is Sales Invoice Header table
     SalesInvHeader.SETRANGE("Pre-Assigned No.",globalvar); // the globalvar that you have assigned at start of OnPush Trigger
     Codeunit.run(YourCodeUnitId,SalesInvHeader);
     clear(globalvar);
    

    I believe this will run after ending the write transaction.... so there wont be any locking proble....

    Try atleast...!!! its better not to touch CU 80...!!!
    Thanks,

    Kashyap
  • BeliasBelias Member Posts: 2,998
    But remember that you can post the invoice from other places other than the post button
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
  • kash387kash387 Member Posts: 111
    Belias wrote:
    But remember that you can post the invoice from other places other than the post button

    Thats absolutely true, but this is what he was asking for...!!!

    He wants to place it on form 43...!!!!
    Thanks,

    Kashyap
  • BeliasBelias Member Posts: 2,998
    not really... :mrgreen:
    bangswit wrote:
    how to execute it automatically after i post Sales Invoice to be Posted Sales Invoiced?
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
  • bangswitbangswit Member Posts: 265
    I have 1 report for generate from table to be txt file
    so how I execute that after posting, without using button "preview" anymore
  • BeliasBelias Member Posts: 2,998
    if you need to run the report after the click of the post button, it's "ok" (let's say that's the easiest solution to do)...
    Belias wrote:
    But remember that you can post the invoice from other places other than the post button
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
  • bangswitbangswit Member Posts: 265
    Belias wrote:
    if you need to run the report after the click of the post button, it's "ok" (let's say that's the easiest solution to do)...
    Belias wrote:
    But remember that you can post the invoice from other places other than the post button

    i'm sorry .. come again?
    i don't understand
    sorry
  • BeliasBelias Member Posts: 2,998
    You can call the report in the post button, just after running in the posting routine.
    but if you post the invoice by not clicking the button (for example, the batch posting report), your code won't be run, and your file not generated...
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
  • bangswitbangswit Member Posts: 265
    Belias wrote:
    You can call the report in the post button, just after running in the posting routine.
    but if you post the invoice by not clicking the button (for example, the batch posting report), your code won't be run, and your file not generated...
    that's okay... because we don't use batch posting report
    but how to execute it without press preview button in that report again...
  • BeliasBelias Member Posts: 2,998
    bangswit wrote:
    Belias wrote:
    You can call the report in the post button, just after running in the posting routine.
    but if you post the invoice by not clicking the button (for example, the batch posting report), your code won't be run, and your file not generated...
    that's okay... because we don't use batch posting report
    but how to execute it without press preview button in that report again...
    it all depends from how do you call the report...just post your code here. Try with function USEREQUESTFORM (or something similar, i don't remember the exact name, search the online help)
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
  • bangswitbangswit Member Posts: 265
    from posted sales invoiced i create code like this
    CurrForm.SETSELECTIONFILTER(SalesInvHeader);
    REPORT.RUN(50092,TRUE,FALSE,SalesInvHeader);
    

    but i want to call it from sales invoice
    after posted and the execute this code
  • BeliasBelias Member Posts: 2,998
    -use a report variable instead of "REPORT.RUN"
    -use functions SETTABLEVIEW, and USEREQUESTFORM
    but why don't ask a senior developer?it would be faster than chatting in mibuso, isn't it?
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
  • bangswitbangswit Member Posts: 265
    Belias wrote:
    -use a report variable instead of "REPORT.RUN"
    -use functions SETTABLEVIEW, and USEREQUESTFORM
    but why don't ask a senior developer?it would be faster than chatting in mibuso, isn't it?

    settableview??
    how to use that?

    hehe i work alone
    dont have senior developer
    poor me...
  • BeliasBelias Member Posts: 2,998
    bangswit wrote:
    poor me...
    not only you, but all the developers that will come after you!and also poor your customer!
    if you don't know these basic instructions (or worse, you don't even know how to find by yourself the way to understand them -> don't you know how to press f1?!?! :?) you should study before implementing NAV. All of us did it, there are no shortcuts!
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
  • bangswitbangswit Member Posts: 265
    Belias wrote:
    bangswit wrote:
    poor me...
    not only you, but all the developers that will come after you!and also poor your customer!
    if you don't know these basic instructions (or worse, you don't even know how to find by yourself the way to understand them -> don't you know how to press f1?!?! :?) you should study before implementing NAV. All of us did it, there are no shortcuts!
    no...
    i already get the code
    i already get the code using settableview also
    and you ask my code
    i just don't know where should i put it
    because, as i know... it's recommended that i don't changet the sales post code unit
    so i'm asking here....
  • BeliasBelias Member Posts: 2,998
    put it in form 43 as you told in of the first post of this topic!
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
  • bangswitbangswit Member Posts: 265
    Belias wrote:
    put it in form 43 as you told in of the first post of this topic!
    i alredy did put this code
    CurrForm.SETSELECTIONFILTER(SalesInvHeader);
    REPORT.RUN(50001,TRUE,FALSE,SalesInvHeader);
    

    but it still show the preview button
  • BeliasBelias Member Posts: 2,998
    ok, i give up...take it easy, but i'm a bit tired of quoting myself...
    Belias wrote:
    -use a report variable instead of "REPORT.RUN"
    -use functions SETTABLEVIEW, and USEREQUESTFORM
    but why don't ask a senior developer?it would be faster than chatting in mibuso, isn't it?
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
  • SavatageSavatage Member Posts: 7,142
    When posting you should have an option to
    1.Post
    2.Post & Print

    Just follow the same logic as post & print.
    Follow the code & see how it's done.

    Looks like someones looking for a 3rd option
    3.Post & Export
  • themavethemave Member Posts: 1,058
    Or a completely different solution, don't do it on the posted invoiced at all. Add a field to the posted invoice table that is just a simple "Data Exported" = true/flase Modify your codeunit a little to have it look at the posted invoice table, and look for posted invoices that haven't been exported yet, and run on those, then updated the field to true. set it to run in the job scheduler or on a timer or some other way, and the standard posting routine doesn't need to be changed, much easier if you ever what to upgrade down the road, or if you decide you want to use batch posting etc. Just an idea, but I try to always look at leaving Navision code standard, since I am an end user, and want to try to make upgrades as easy as possible.
  • AndwianAndwian Member Posts: 627
    Have you set the ProcessOnly to Yes on Report Properties?
    Regards,
    Andwian
  • vaprogvaprog Member Posts: 1,139
    bangswit wrote:
    that's okay... because we don't use batch posting report
    Don't do this! Never ignore NAV standard functionality, just because you don't use it at the moment, unless effort and expense is high and the customer demands it (in written form). Even then you should add code to disable "unused" features you did exclude from your customisation, or at least warn the user that something will go wrong if he uses that feature without further customistion.
    If you ignore this, at some point, technical and/or legal adversities will overtake you.
Sign In or Register to comment.