Documents got posted by mistake? Generate them back [from posted document]

How much time it will take to recreate an Unposted Purchase invoice from a Posted invoice keeping all information intact?

Well, that’s a no brainer! You can simply use ‘copy document‘ function in Purchase Invoice window. Keep ‘Include Header‘ ticked & ‘Recalculate Lines‘ not ticked [this will retain same vendor for header & same information from lines]

But what about if you need to do the same 400 times?

Let me give you the background from where I am coming from. Right now I am helping a company in Bracknell, UK [the silicon valley of UK] with lot of enhancements. And they seems pretty excited [first time it’s realised that they can do so much more from their almost obsolete system (they are using NAV 2009 classic)]

I am not going to talk about what kind enhancements / automation I did for them in this post rather will speak about what happened today morning when their CFO rushed to me and informed me that the purchase lady by mistake posted all the unposted invoices pending in the system instead of posting invoices pertaining to only a particular vendor [She executed ‘Post batch‘ and forgot to mention the ‘Buy-from Vendor No.‘ filter in the request form.

CFO: Can you do something about it? I will take necessary steps to reverse the financial impacts of those invoices but can you help me in recreating those unposted purchase invoices?

I said ‘Yes‘ and here what I did:

A. Study the ‘Copy Purchase Document’ function:

I have used this function plenty of times and understand technically what exactly it is doing. But hardly ever I had gone into the details or checked the code written there [Report 492]. So basically what it does –

Copy Document Flow

This works for one document. Question is ‘How to automate it for multiple documents [in this case 400]?

B. Gather the information:

Post study, i concentrated on gathering information about documents wrongly posted [I need to recreate new unposted purchase invoices copying info from these documents only].

CFO promptly shared me a list of wrongly posted invoices in excel. Though he shared me lot of additional info for this process I needed only the posted invoice nos. So I decided to put this info in a Dynamics NAV table and created it with following structure –

1. Invoice No. [Code 20]- This will hold the posted invoice nos.

2. Recreated [Boolean] – This will be marked ‘true’  if an unposted purchase order gets created successfully.

3. PO Created [Code 20] – to store the corresponding unposted purchase invoice created by the report (don’t bother about the naming convention).

 

Created a dataport and imported the list in this table [How to create a dataport and import these info into a table is out of scope of this post]

C. Build the Automation :

Now I have all the information and it’s time to automate a process which will read through these invoices and call the ‘Copy Document’ again and again for each posted invoice.

To build this, I could use a codeunit, a form or a report. And I choose a report [probably I felt it’s simpler to manage].

So I created a ‘ProcessingOnly‘ report with the DataItem = the table I created above in step B. Below is the DataItem properties, Report Properties, Global variables defined and the Code written in the report

  • DataItem Properties
  • Report Properties
  • Global Variables
  • Code written

Below is the explanation of the code:

D. Run the Report:

Run the report and at the end of it, it will display you ‘how many invoices are regenerated’. This will also update your custom table with ‘Recreated’ tag true and corresponding Invoice No generated –

 

 

 

 

Report is successfully run and the records are updated.

 

Voila, all invoices which was posted wrongly are recreated. Check them up. Remember there will be an additional line [first line] in all newly created unposted Purchase Invoices mentioning the posted invoice no [source document] from where it is recreated [see below screenshot]

Hope this helps if you come across a similar situation. You can download the zipped objects created by me here or from my Downloads section. You can actually modify them to suit your requirements or even for other module to manage similar situation.

In case of any confusion / queries, do write to me [snehanshu@dynaexperts.com] or put your comments below.

Cheers!

2 Replies to “Documents got posted by mistake? Generate them back [from posted document]”

Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.