Announcements
Hello I have a task.
I want to run a X++ job that much identify a folder say in C drive. The folders will be numbered like personnel numbers in HcmWoker table. Each folder may consists of some files of types PDF,word,jpeg and so on.
The X++ job must go to the particular folder and add all these files as attachments to the particular record numbered according to the folder name(personnel number).
Can anybody give some ideas? How I can begin? Or C# is suitable for this? Or you have X++ code?
For the movement I am able to attach documents when I run the X++ job, I will browse manually and find the file and attach it to the document.
Now I wanted this process must get automated that whenever I run the Job the job must automatically go and upload all the files.
No trouble - Am glad your requirement get resolved. CHeers
Yes Fareed. I was not able to see your solution. But I will try to use later the execution time calculation which is used in the link you have given.
Excellent - it worked for you.
Thanks to all for your help.
Hi Baber and all,
By following different things I am able to attach documents.
Now the context is that I want to attach certificates for the employees in HcmWorker table may contain documents like scanned certificates(jpeg,mpeg) PDF files and so on.
The documents will be arranged in a folder named according to the personnel number field in HCMWorker table like 000001,000542 and so on. In each of these folders documents to be uploaded for each employee will be there.
Next thing. What maximum file sizes combinedly can I attach? All other ideas as per your experiences?
Hi Mahesh,
Recenlty, I did the same thing in one of the project I was working on. Below is the code to traverse through the directory and return the files in container variable:
private container getListOfImportFiles()
{
System.Array files;
InteropPermission permission;
counter fileCounter;
container fileList;
;
permission = new InteropPermission(InteropKind::ClrInterop);
permission.assert();
files = CLRInterop::staticInvoke("System.IO.Directory", "GetFiles", YourDirectoryPath, "*.csv");
for (fileCounter = 0; fileCounter < ClrInterop::getAnyTypeForObject(files.get_Length()); fileCounter++)
{
fileList = conins(fileList, conLen(fileList)+1, ClrInterop::getAnyTypeForObject(files.GetValue(fileCounter)));
}
CodeAccessPermission::revertAssert();
return fileList;
}
After this, you can write the code to read the files one by one. Code is shown below:
FileName importFileName;
Counter counter;
container fileList;
FileIOPermission permission;
CommaTextIo file;
container line;
int recordCount;
if (conlen(fileList) > 0)
{
for (counter =1; counter <= conlen(fileList); counter++)
{
importFileName = conPeek(fileList, counter);
permission = new FileIOPermission(importFileName, "RW" );
permission.assert();
file = new CommaTextIo(importFileName, #io_read);
if (!file || file.status() != IO_Status::Ok)
{
throw error("File not found");
}
file.inFieldDelimiter(',');
line = file.read();
while (file.status() == IO_Status::Ok)
{
recordCount++;
// process the file here by using the container variable 'line'
line = file.read();
}
file = null;
CodeAccessPermission::revertAssert();
} // End for loop
} // End outer If clause
For document attachment, refer to the below code:
private void attachDoc(RefTableId _refTableId, RefRecId _refRecId, selectableDataArea _refCompanyId, FileName _name)
{
DocuRef docuRef;
DocuActionArchive archive;
FileName fileName;
;
// Get the file name only.
fileName = conPeek(fileNameSplit(_name), 2);
docuRef.clear();
docuRef.RefRecId = _refRecId;
docuRef.RefTableId = _refTableId;
docuRef.RefCompanyId = _refCompanyId;
docuRef.Name = fileName;
docuRef.TypeId = YourTypeID;
docuRef.insert();
archive = new DocuActionArchive();
archive.insertDocuValue(docuRef, _name);
//archive.add(docuRef, _name);
}
Please verify and let me know if you have further queries.
Thanks,
Baber.
I will check it Faisal.
Hi Mahesh,
I did this bit of work few days ago and blog it here daxture.blogspot.com.au/.../retrieving-files-from-directory-through.html
For attaching it as attachments please have a look on DocuRef class as suggested by Rachit in above link.
If you need more help please do let me know
Okay Rachit Garg and jens I will try it.
Check the WINAPI class, it contains functions to operate Folders.
There are also .NET functions you can use e.g. check out the System.IO.Directory Namespace/class.
To attach the document to a record you have to create the Docu* table records (DocuRef, DocuValue,...).
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 290,186 Super User 2024 Season 2
Martin Dráb 227,996 Super User 2024 Season 2
nmaenpaa 101,148