I want to attach file to invoice so :
1. I add new field in salesparmTable
2.I add this field in salesEditLines form :

3.When I click on button ok and checkBox"Archiver doc" =yes :

4.then when I post invoice I don't find the attach file in account receivable > invoices > invoice journal :

this is my code :
[FormControlEventHandler(formControlStr(SalesEditLines, OK), FormControlEventType::Clicked)]
public static void OK_OnClicked(FormControl sender, FormControlEventArgs e)
{
AsciiStreamIo file;
Array fileLines;
FileUploadTemporaryStorageResult fileUpload;
CustInvoiceJour custInvoiceJour;
DocuType docuType;
DocuRef docuRef;
DocuValue docValue;
FormCommandButtonControl callerButton = sender as FormCommandButtonControl; //Retrieves the button
FormRun form = sender.formRun(); //Gets the running form
//Get the salesParmTable datasource that was selected in form
FormDataSource salesParmTable_ds = form.dataSource(formDataSourceStr(SalesEditLines, SalesParmTable)) as FormDataSource;
SalesParmTable salesParmTable = salesParmTable_ds.cursor();
Info(strFmt("account: %1, check: %2 ",salesParmTable.InvoiceAccount,salesParmTable.ILBArchiveDoc));
select * from custInvoiceJour where custInvoiceJour.InvoiceAccount==salesParmTable.InvoiceAccount && custInvoiceJour.SalesId==salesParmTable.SalesId;
Info(strFmt("recId: %1 ",custInvoiceJour.RecId));
if( salesParmTable.ILBArchiveDoc == NoYes::Yes )
{
fileUpload = file::GetFileFromUser() as FileUploadTemporaryStorageResult;
Info(strFmt("nom du fichier %1",fileUpload.getFileName()));
Info("good");
ttsbegin;
docValue.clear();
docValue.FileName = fileUpload.getFileName();
docValue.FileType = docuType.TypeId;
docValue.insert();
Info(strFmt("docValue %1",docValue.RecId));
docuRef.clear();
docuRef.RefCompanyId = custInvoiceJour.dataAreaId;
docuRef.ValueRecId = docValue.RecId;
docuRef.RefTableId = custInvoiceJour.TableId;
docuRef.RefRecId = custInvoiceJour.RecId;
docuRef.Name = 'Automatic file for sales order 001512';
docuRef.Notes = 'Added from X by baw';
docuRef.insert();
ttscommit;
info("Document note has been added successfully");
}
}