Tuesday, January 26, 2016

"This voucher number already exists" when trying to open a saved Payables Invoice

By Steve Endow

Tonight I'm testing some changes to a GP VS Tools AddIn that I developed.

I apparently had a bug in a line of the AddIn code that caused GP to crash while I was editing a Payables Invoice.


So I fixed the bug, recompiled, and opened GP again, clearing out my old login record.

Strangely, when I opened the Payables Transaction Entry window and clicked on the 'last' record button, nothing happened.  Using the First/Previous/Next/Last buttons wasn't bringing up my test invoice.  Odd.

I then tried the lookup button next to the voucher number field.  There was the invoice.  Hmmm.


But when I tried to select the invoice to open it, I received this message.


Um, ya, of course the voucher number already exists!  It's a saved voucher!

So apparently the GP crash caused some problem that is preventing GP from opening the voucher.

To start my detective work, I closed the Payables Transaction Entry window, and I checked DEX_LOCK, SY00800, and SY00801.  Nothing.

Then I opened the window again and traced the SQL activity that occurred when I selected the saved voucher.  Nothing obvious that I could decipher.

I then queried PM00400 and saw a small oddity--voucher 680 had a blank record, and I hadn't attempted to save it.  It wasn't obvious if that might be related, but it does look like an invalid record.


I also noticed that the REBILL batch to which the invoice belongs has a transaction count of 2, even though there is only one transaction in the batch.  I've done lots of testing and had several GP crashes, so I am guessing the transaction count was already wrong.


So, as a last resort, I entered a new voucher so that I could compare the data for that new record to my problem voucher.

And that's when I saw an issue.


Voucher 680 had a document status of 0.  Even though the voucher had been previously saved, when GP crashed, it somehow caused the document status for the voucher number to be set to 0 in the PM Keys table.

I can proudly say that I have crashed GP hundreds, nay, thousands of times with my test code, and have never seen this issue.

So I set the DCSTATUS value to 1 and tried opening the voucher.  Nope.  Same error.

So then I queried PM10000 to see if I could find any odd values.

I found that the PSTGSTUS field was indicating that the voucher was being edited.  Which makes sense.


After setting the posting status back to 20, I was finally able to open the voucher again.

That was a fun waste of 30 minutes.

It'll teach me to never have a bug again.  My first and only bug.


Steve Endow is a Microsoft MVP for Dynamics GP and a Dynamics GP Certified IT Professional in Los Angeles.  He is the owner of Precipio Services, which provides Dynamics GP integrations, customizations, and automation solutions.

You can also find him on Google+ and Twitter










No comments: