Showing posts with label mass. Show all posts
Showing posts with label mass. Show all posts

Sunday, October 12, 2025

Mass export employee photos

Recently was trying to figure out how to mass download/export employee photos from PeopleSoft and followingis what I came up with. It works but the exported image quality is not that great. We are using the delivered application engine HR_EMPLPHOTO to mass import picutes in. The photos are loaded to PS_EMPL_PHOTO table and it creates four photo sizes - CARD, LIST, ORCH and PAGE. The CARD one is the best in terms of picture quality.

The basic idea is to read this table and write the contents to a file. Based on the upload process I know that the picture file format is JPG. The raw image data is stored in the EMPLOYEE_PHOTO field, but we cannot just select this field. I am looping through the employee population, fetching the data and storing it in the record object and then using the WriteRaw method of the File class to write the image to a file. 


Local string &emplid, &filename;
Local Record &imageRec;
Local SQL &imageSQL;

&imageRec = CreateRecord(Record.EMPL_PHOTO);
&imageSQL = CreateSQL("SELECT EMPLID, PHOTO_SIZENAME, PHOTO_IMGNAME, EMPLOYEE_PHOTO, PSIMAGEVER FROM PS_EMPL_PHOTO WHERE EMPLID = :1 AND PHOTO_SIZENAME = 'CARD'", &emplid);

If &imageSQL.Fetch(&imageRec) Then
   &imageFile = GetFile(&filename, "W", %FilePath_Absolute);
   &imageFile.WriteRaw(&imageRec.EMPLOYEE_PHOTO.Value);
   &imageFile.Close();
End-If;

Monday, March 6, 2023

Mass upload/download files

Recently I was presented with a requirement wherein the user should be able to mass upload files from their local workstation to PeopleSoft and then mass download the files from PeopleSoft to their local workstation. The files would be stored in the database record.

I am running PT 8.59.x and PeopleSoft does provide a couple of functions MAddAttachment and DetachAttachment for this exact requirement. 

The MAddAttachment function is pretty straight forward. I was able to call it via FieldChange event, where in a dialog box is presented to the user to select a single file or multiple files and the files are loaded to the URL value provided as part of the function parameter. The function also has a parameter which can limit the number of files uploaded at a time. Just like the AddAttachment function this function also converts the filenames which have special characters like a space, amersand, plus sign etc. to underscores. More info about this under the "Understanding the File Attachment Functions" and "File Name Considersations" section in Peoplebooks.

For my requirement I was displaying the files loaded via MAddAttachment in a grid on the page. Now I provided another button, and on FieldChange of this button the plan was to invoke DetachAttachment to run through the files in the grid and download them locally to the user's workstation. For some reason this does not work. The code would run through the grid but would download only the last file in the grid, no errors anywhere.  So following is what I did to get around this limitation.

I am using GetAttachment first to read through the grid rowset and download the files to a temporary location on the server. I am programmatically creating a folder structure to download the files to. Then I am using java clases to compress or zip up the files in the temporary folder. Process to compress files available here. Then I am using PutAttachment function to upload the single compressed/zip file back into the database. Finally I am calling DetachAttachment to download the compressed/zip file to the user's local workstation. As part of post-cleanup I am using DeleteAttachment to delete the compressed/zip file from the database and then using RemoveDirectory to delete the temporary location created on the sevrer to download the files to.