Batch Archive

supp85supp85 Member Posts: 76
Hello all,

I am trying to create a report to batch archive quotes however i'm not entirley sure how to go about it, can anyone help please?

Thank you

Comments

  • DenSterDenSter Member Posts: 8,304
    Here's how you would go about doing something like that:
    • First you do the process manually, to understand how it works. This will tell you where to look when you start automising this process.
    • So, create a quote, and archive it manually.
    • Open the objects in design mode and figure out what objects are involved.
    • Run Code Coverage to get a list of all the objects.
    • Run the debugger and step through the code. This is probaby the most useful way to get a real grip on how it works
    • Then when you have figured out what the process is, which steps you have to go through, you can write the C/AL code to automate the process
    Just to give you a small idea: You'd create a processing only report that goes off of the Sales Header or Purchase Header (you didn't specify if it was sales or purchase quotes), so you add that table as the top data item. The actual archiving takes place in the ArchiveManagement codeunit. You would write the code that actually archives the quotes in the OnAfterGetRecord trigger of the dataitem.
  • supp85supp85 Member Posts: 76
    I think i may have done it woo hoo!! I entered the following code within the OnAfterGetRecord trigger:

    SalesHead.SETRANGE("Document Type","Document Type"::Quote);
    SalesHead.SETRANGE("Sales Quote Status","Sales Quote Status"::Lost);
    SalesHead.SETRANGE(Status, Status::Released);

    ArchiveManagement.StoreSalesDocument("Sales Header",TRUE);
    DELETE(TRUE);

    It seems to be working however if you do see any flaws within it please do let me know.
  • supp85supp85 Member Posts: 76
    Thank you for your reply Denster appreciate it
  • DenSterDenSter Member Posts: 8,304
    supp85 wrote:
    I think i may have done it woo hoo!! I entered the following code within the OnAfterGetRecord trigger:

    SalesHead.SETRANGE("Document Type","Document Type"::Quote);
    SalesHead.SETRANGE("Sales Quote Status","Sales Quote Status"::Lost);
    SalesHead.SETRANGE(Status, Status::Released);

    ArchiveManagement.StoreSalesDocument("Sales Header",TRUE);
    DELETE(TRUE);

    It seems to be working however if you do see any flaws within it please do let me know.
    You're welcome, always glad to be able to help. That code doesn't look like it would work though. You set filters on something called "SalesHead", and you send the "Sales Header" into the archivemanagement codeunit. Those look like they are two different variables, so that won't work I don't think.

    In general, you would typically not program filters in the OnAfterGetRecord trigger. Either you program filters in the OnPreDataItem trigger, or you let the user set filters in the Sales Header request form.
  • kapamaroukapamarou Member Posts: 1,152
    One suggestion.

    If there is no commit in the code that is executed, it would be nice to place a commit between each quote and maybe a SLEEP for a couple of seconds, just to make sure you don't block anyone. If you have a lot of quotes and the batch job needs a lot of time you might delay the rest of the processes. I've done the same not only with archiving, but also with posting, so it can be done...
  • krikikriki Member, Moderator Posts: 9,110
    [Topic moved from 'NAV Tips & Tricks' forum to 'NAV/Navision' forum]
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • supp85supp85 Member Posts: 76
    Thank you both for your replies, they are actually the same Variable not quite sure why i named them differently, I agree with moving the filters to the OnPreDataItem trigger thank you, just a quick question in regards to the filter, would it be better to i apply them within the report properties?

    I'll try out the commit function, just not sure whether it would be worthwhile as the report wouldn't be used very frequently.
  • DenSterDenSter Member Posts: 8,304
    Different variable names means different variables, the computer doesn't know that you mean to use the same one.

    If those filters are supposed to always be used then I'd personally set them in the DataItemTableView property of the dataitem.
Sign In or Register to comment.