internal final class SaveImageFromTableToLocalFile
{
/// <summary>
/// Class entry point. The system will call this method when a designated menu
/// is selected or when execution starts and this class is set as the startup class.
/// </summary>
/// <param name = "_args">The specified arguments.</param>
public static void main(Args _args)
{
HcmWorker hcmWorker;
HcmPersonImage personImageTable;
container imageContainer;
str filePath;
int fileSize;
SysParameters sysParameterTable;
FilePath staticParameterFilePath;
BinData bin;
boolean isSuccess = false;
sysParameterTable = SYSParameterTable::find();
staticParameterFilePath = sysParameterTable.StaticFilePath; // New Field, EDT: FilePath
if (!staticParameterFilePath)
{
throw error ("Specify file Path in System Parameter form to download employee images.");
}
while select hcmWorker
{
// Retrieve the image data from your table
select personImageTable where personImageTable.Person == hcmWorker.Person;
// Check if the image data exists
if (personImageTable.Image != conNull())
{
//filePath = strFmt("C:\\temp\\%1.jpg", hcmWorker.PersonnelNumber);
bin = new BinData();
filePath = strFmt(staticParameterFilePath +"\\%1.jpg", hcmWorker.PersonnelNumber);
imageContainer = personImageTable.Image;
fileSize = conLen(imageContainer);
bin.setData(imageContainer);
bin.saveFile(filePath);
isSuccess = true;
}
}
if (isSuccess)
{
info(strFmt("Files are saved in given static file path: %1", staticParameterFilePath));
}
}
}