Quantcast
Channel: Microsoft Dynamics AX Forum - Recent Threads
Viewing all articles
Browse latest Browse all 175888

import document as attachment

$
0
0

Hy everybody, below you could find a simple job to read document from a folder and insert as attachment.

Obviously could be improved with parameters and dialogbox or transform it as a batch class that search in a specify folder ...

please beware about the WINAPI is you will use on server execution.

Bye, Daniele.

static void ImportDocument(Args _args)
{
#WINAPI
DocuRef docuRef;
DocuActionArchive archive;
InventTable inventTable;
ItemId itemid;

str 200 _filepath,filename,impfile;
real filehandle;
str 200 tmppath, tmpname, tmpext;
str _name;
;

select docuRef where docuRef.RefTableId == tablenum(inventtable);

_filepath = @"<path container of files to attachment>";
if (WinApi::folderExists(_filePath))
{
[fileHandle, fileName] = WinApi::findFirstFile(_filepath + '\\' + "<search pattern ex. *.PDF>");

while (fileName)
{
[tmppath, tmpname, tmpext] = fileNameSplit(filename);

inventtable = inventTable::find(subStr(tmpname,1,8));
if(tmpname && inventTable.recid)
{
ttsBegin;

docuRef.clear();
docuRef.RefRecId = inventTable.RecId;
docuRef.RefTableId = tableNum("inventtable");
docuRef.RefCompanyId = curext();
docuRef.Name = tmpname;
docuRef.TypeId = //TODO : specify the type of document;
docuRef.insert();
archive = new DocuActionArchive();
archive.add(docuRef, _filepath + '\\' + fileName);

ttsCommit;
}
fileName = WinApi::findNextFile(fileHandle);
info(filename);
} //end of inner while
}//End
}


Viewing all articles
Browse latest Browse all 175888

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>