Page 1 of 1

Adding a document to a processed sales order

PostPosted: Fri Jul 17, 2020 3:37 pm
by SBarnes
I had asked the question about adding an attachment to an emailed order here viewtopic.php?f=26&t=1335

This works fine when firing off the email from the process end but what I would now like to be able to do is add the csv file to the documents collection on the sales order but the following code produces an error, is there any way to make this happen as it appears you can't do it through the UI either?

Code: Select all

               JiwaFinancials.Jiwa.JiwaApplication.Documents.Document sdoc = salesorder.Manager.CollectionItemFactory.CreateCollectionItem<JiwaFinancials.Jiwa.JiwaApplication.Documents.Document>();
                  sdoc.FileBinary = System.IO.File.ReadAllBytes(FileName);
                  sdoc.Description = "Invoice csv";


                    sdoc.DocumentType = salesorder.Documents.DocumentTypes.GetDefaultDocumentType();
                    sdoc.PhysicalFileName = FileName;
                  salesorder.Documents.Add(sdoc);               
               
               salesorder.Save();

Re: Adding a document to a processed sales order  Topic is solved

PostPosted: Sun Jul 19, 2020 6:32 pm
by SBarnes
To answer my own question here the easiest way around this ended up being in the process start event create the file attach it to the order there as well as in the email, if the process ends up failing then nothing gets attached to the order because its never saved, the emailing still needs to stay in the process end because this should only happen on success.

At the end of the day it meant creating the file twice but it's the simplest answer.