Page 1 of 1

Copy SO - Documents

PostPosted: Wed Dec 23, 2020 2:24 am
by Riyaz
Hi There

When we use the Copy function of the sales order the document record gets copied to the destination, but the file cant be opened. On checking I noticed that the FileBinary ends up as NULL for that document. I've tried to update as a plugin and via trigger but its not successful. I either get an error, or the new Sales Order wont get saved at all. Can you pls guide here.

Re: Copy SO - Documents

PostPosted: Wed Dec 23, 2020 8:01 am
by SBarnes
Given I just tried this on a demo database with the system setting to copy the documents over turned on under invoicing and you then try and open or save the document on the copied order, Jiwa produces a null reference exception I suspect you have come across a bug but Jiwa would need to confirm this as likewise in my demo database the file binary is also null for me.

If I was looking to get around this in the copy start event I would make my own copy of the documents into the sales order objects generic object collection and then in the copy end event clear the documents Jiwa had created and then add the ones back in from the data in the generic object collection by creating a new document from the old one and adding it to the documents collection.

Re: Copy SO - Documents  Topic is solved

PostPosted: Wed Dec 23, 2020 8:52 am
by Scott.Pearce
Logged as DEV-4705.

At some point we introduced a property to the document class named "FileBinaryChanged". This was done for performance reasons - why save a potentially huge binary to the database if it hadn't actually changed? (maybe only the document Description was changed). Only when the FileBinary property is set for a document does FileBinaryChanged get set to true.

Now when a copy is performed, we simply generate a new RecID for a document and set it's InsertFlag to true. Voila. Copied. Unfortunately, we must have failed to update the copy method for documents when we introduced the FileBinaryChanged flag, so the copy does not push the file binary to the database upon save because we failed to set FileBinaryChanged to true during the copy process.

I've attached a plugin to workaround this issue. It simply sets FileBinaryChanged to true for all documents in the sales order copy end event:

Plugin Sales Order Copy Documents Fix.xml
(34.29 KiB) Downloaded 612 times

Re: Copy SO - Documents

PostPosted: Wed Dec 23, 2020 7:37 pm
by Riyaz
All good, thanks Scott and Stuart