I copied the DocuActionArchive class and modified the add method as Shohaib suggested in another thread. Below is the code which I tested and works. I added another parameter so we could use it on the server and client. It still needs a little work as you can see when running on the server, and the attachFilename is null it may fail. I didn't test this case. It works the way it is for what we needed it for.
void add(DocuRef _docuRef, Filename _filename = '', boolean _runOnServer = false)
{
Filename attachFilename;
Filename docuFilename;
Filename onlyFilename;
container fileName;
boolean docuRules;
DocuRef docuReference;
int fileSize;
boolean isFileSizeOk;
int hWnd = 0;
Microsoft.Dynamics.AX.Framework.OfficeAddin.SharePoint.AuthenticationType docuAuthType;
#File
#XppTexts
// PBA begin
attachFilename = _filename;
if(!attachFilename && !_runOnServer)
// PBA end
{
if (_docuRef.dataSource() != null && _docuRef.dataSource().formRun() != null)
{
hWnd = _docuRef.dataSource().formRun().hWnd();
}
attachFilename = WinAPI::getOpenFileName(
hWnd,
["@SYS26054", #AllFiles], /* *.* */
#emptyString,
"@SYS26798");
}
if (! attachFilename)
return;
fileName = Docu::splitFilename(attachFilename);
_docuRef.Name = conpeek(fileName, 1);
_docuRef.doUpdate();
[onlyFilename,curFileType] = Docu::splitFilename(attachFilename);
docuRules = Docu::validateExtension(curFileType);
isFileSizeOk = true;
if (docuRules)
{
if(_runOnServer)
{
fileSize = WinAPIServer::fileSize(attachFilename);
}
else
{
fileSize = WinAPI::fileSize(attachFilename);
}
isFileSizeOk = Docu::validateFileSize(_docuRef.docuType() ,fileSize);
}
if (!docuRules || !isFileSizeOk)
{
ttsbegin;
docuReference = DocuRef::findRecId(_docuRef.RecId, true);
docuReference.delete();
ttscommit;
if (_docuRef.dataSource())
{
_docuRef.dataSource().reread();
_docuRef.dataSource().refresh();
}
if (!docuRules)
error("@SYS99219");
else
error("@SYS97286");
return;
}
super(_docuRef);
if (this.mustArchiveFiles())
{
docuFilename = _docuRef.path()
+ onlyFilename
+ #FileNameDelimiter
+ smmDocuments::getNonExistingFileName(numSeq,_docuRef.path(),this.fileType())
+ #FileExtensionDelimiter
+ this.fileType(); //new Filename
//uses curFileType
if (_docuRef.docuType().FilePlace == DocuFilePlace::SharePoint)
{
docuAuthType = DocuSharePointParameters::ConvertAuthenticationType(DocuSharePointParameters::GetAuthenticationType(docuFilename));
Microsoft.Dynamics.AX.Framework.OfficeAddin.SharePoint.DocumentUploader::UploadDocument(attachFilename, new System.Uri(docuFilename), docuAuthType, false);
}
else
{
if(_runOnServer)
{
WinAPIServer::copyFile(attachFilename, docuFilename);
}
else
{
WinAPI::copyFile(attachFilename, docuFilename);
}
}
}
else
{
docuFilename = attachFilename;
}
this.insertDocuValue(_docuRef,docuFilename);
curFileType = #emptyString;
}