I have files stored in an SQL table, and I am using a stored procedure to retrieve them. The files contain the following information:
- Document Type
- File Name
- File Content
- Status (0 or Pending)
The stored procedure gets the data from the SQL table, and I’m mapping the Employee ID to the PersonnelNumber in the HCMWorker
table to get the RecId of that employee. The RefTableId is always 6266
.
My challenge is how to pass the data to the FileUpload the REFTABLEID and REFCOMPANYID
NAME
NOTES
PARTY
REFRECID
REFTABLEID
TYPEID
This is the code i have so far
public static void UploadEmployeeFiles()
{
SqlDataReader sqlDataReader;
int refTableId = 6266;
RecId refRecId;
sqlDataReader = CallStoredProcedure("GetPendingFiles");
while (sqlDataReader.Read())
{
str fileName = sqlDataReader.GetString("FileName");
str fileContentBase64 = sqlDataReader.GetString("FileContent");
str documentType = sqlDataReader.GetString("DocumentType");
str employeeId = sqlDataReader.GetString("EmployeeID");
// Get RecId for the employee
refRecId = GetEmployeeRecId(employeeId);
// Convert file content to a stream
System.IO.Stream fileStream = Base64::base64DecodeToStream(fileContentBase64);
// Create a new FileUpload instance
FileUpload fileUpload = new FileUpload();
// Set the file upload properties
fileUpload.fileName(fileName);
fileUpload.fileStream(fileStream);
fileUpload.setEncryptionPurposes(documentType);
// Perform the file upload and encryption
fileUpload.upload();
}
}
// Helper method to get Employee RecId
private static RecId GetEmployeeRecId(str employeeId)
{
HCMWorker hcmWorker;
select RecId from hcmWorker
where hcmWorker.PersonnelNumber == employeeId;
return hcmWorker.RecId;
}
1 Like