Saturday, 11 June 2011
PeopleSoft Employee Photo Load conversion program
Employee photo are loaded in the record PS_EMPL_PHOTO.
New feature in 9.1 : Company Directory also publish the photo from PS_EMPL_PHOTO.
Steps to achieve this:
Note:Employee photo are saved with the same emplid.jpg eg. 12345.jpg
Step 1: Create an application engine program with one section with one action =peoplecode
Step 2:Copy paste the below code it will work .
<**************************************************************************************************************************
This function initializes employee photo processing.
It initializes PSOPTIONS.MAXCHUNKSIZE.
The point of the initialization is to select a chunk size that is larger than the largest photo that will be processed.
The processing chunksize is currently set to 1MB. The program would need to be updated if a larger photo is to be loaded.
The original chunksize should be noted as it is possible for the program to abend without restoring the original chunksize
(28K as of this writing).**************************************************************************************************************************>
Function PutPhotoTerm()
If &iOriginalChunkSize < &iPhotoChunkSize Then
SQLExec("UPDATE PSOPTIONS set MAXCHUNKSIZE = :1", &iOriginalChunkSize);
End-If;
MessageBox(0, "", 0, 0, " %1 employee photos committed.", &iPhotoCnt);
CommitWork();
End-Function;
<**************************************************************************************************************************
This function terminates employee photo processing.
It restores PSOPTIONS.MAXCHUNKSIZE to the value that it had when processing began.
The original chunksize should be noted as it is possible for the program to abend without restoring the original chunksize
(28K as of this writing).**************************************************************************************************************************>
Function PutPhotoInit()
SQLExec("SELECT MAXCHUNKSIZE FROM PSOPTIONS", &iOriginalChunkSize);
&iPhotoChunkSize = 1000000;
If &iOriginalChunkSize < &iPhotoChunkSize Then
SQLExec("UPDATE PSOPTIONS set MAXCHUNKSIZE = :1", &iPhotoChunkSize);
End-If;
&recEMPL_PHOTO = CreateRecord(Record.EMPL_PHOTO);
End-Function;
<**************************************************************************************************************************
This function actually loads the photo.
1)The photo file is first loaded to PSFILE_ATTDET using the PutAttachment function.
2)The blob data of the photo is then selected into a variable using SQLExec();
3)The photo file row is then deleted from PSFILE_ATTDET.
4)PS_EMPL_PHOTO.PSIMAGEVER is set to the number of seconds since 01-JAN-2000.
5)The row is is updated or inserted on PS_EMPL_PHOTO depending on whether the employee ID already exists.
6)A commit is performed every 50 rows.**************************************************************************************************************************>
Function PutPhoto()
Local integer &iVersion, &iResult;
Local string &strAttachFileName;
Local string &strMsg;
Local any &anyPhotoBlob;
Local boolean &bFound;
&recEMPL_PHOTO.SetDefault();
&strAttachFileName = &strImageEmplid | ".txt";
&iResult = PutAttachment("record://PSFILE_ATTDET", &strAttachFileName, &strImageFileFullName);
If &iResult <> 0 Then
MessageBox(0, "", 0, 0, "*** Start Message ***");
MessageBox(0, "", 0, 0, "PutAttachement failed");
MessageBox(0, "", 0, 0, "Return Code=%1", &iResult);
MessageBox(0, "", 0, 0, "Image File=%2", &strImageFileFullName);
MessageBox(0, "", 0, 0, "Blob File=%3", &strAttachFileName);
MessageBox(0, "", 0, 0, "*** End Message ***");
CommitWork();
End-If;
SQLExec("SELECT FILE_DATA FROM PSFILE_ATTDET WHERE ATTACHSYSFILENAME = :1 AND VERSION = 1", &strAttachFileName, &anyPhotoBlob);
SQLExec("DELETE FROM PSFILE_ATTDET WHERE ATTACHSYSFILENAME = :1 AND VERSION = 1", &strAttachFileName);
REM MessageBox(0, "", 0, 0, "&strImageEmplid=" &strImageEmplid);
&recEMPL_PHOTO.EMPLID.Value = &strImageEmplid;
&bFound = &recEMPL_PHOTO.SelectByKey();
&recEMPL_PHOTO.EMPLID.Value = &strImageEmplid;
&recEMPL_PHOTO.EMPLOYEE_PHOTO.Value = &anyPhotoBlob;
/* Set the version to seconds from year 2000 */
&recEMPL_PHOTO.PSIMAGEVER.Value = (Days365(Date3(1999, 12, 31), %Date) * 86400) + (%Time - Time3(0, 0, 0));
If &bFound Then
&recEMPL_PHOTO.Update();
Else
&recEMPL_PHOTO.Insert();
End-If;
If Mod(&iPhotoCnt, 50) = 0 Then
MessageBox(0, "", 0, 0, " %1 employee photos committed.", &iPhotoCnt);
CommitWork();
End-If;
End-Function;
<**************************************************************************************************************************
This code drives the program. It
1) Retrieves an array of the filenames in /filepath/pooja/ that have a (.jpg) extension.
2) If no files are found the processing is complete.
3) On the first loop iteration, PutPhotoInit() is called to prepare for images to be inserted.
4) For each file name in the array
a) The array entries contain the full path, e.g., /filepath/pooja/12345.jpg.
The directory is removed leaving only the filename 12345.jpg.
b) For each employee ID the image file is saved to the database by calling PutPhoto();
5) After the loop is complete PutPhotoTerm() is called to reset back to pre-run state.**************************************************************************************************************************>
<* Load list of image file names into array *>
&arrImageFileList = FindFiles("/filepath/pooja/*.jpg", %FilePath_Absolute);
If &arrImageFileList = Null Then
MessageBox(0, "", 0, 0, "No files found");
Else
MessageBox(0, "", 0, 0, "found %1 photo files.", &arrImageFileList.Len);
For &iIdx = 1 To &arrImageFileList.Len
&strImageFileFullName = &arrImageFileList [&iIdx];
&strImageFileName = &strImageFileFullName;
If &iPhotoCnt <= 0 Then
PutPhotoInit();
&iPhotoCnt = 1;
Else
&iPhotoCnt = &iPhotoCnt + 1;
End-If;
MessageBox(0, "", 0, 0, "Processing file %1 %2 :", &iPhotoCnt, &strImageFileFullName);
&strImageEmplid = "";
<* remove the path to extract the simple file name *>
&iStartPos = Find("/", &strImageFileName);
If &iStartPos > 0 Then
&iLastSlashFoundPos = &iStartPos;
&iStartPos = &iStartPos + 1;
Else
&iLastSlashFoundPos = 0;
End-If;
While &iStartPos > 0
&iStartPos = Find("/", &strImageFileName, &iStartPos);
If &iStartPos > 0 Then
&iLastSlashFoundPos = &iStartPos;
&iStartPos = &iStartPos + 1;
Else
Break;
End-If;
End-While;
If &iLastSlashFoundPos > 0 Then
&strImageFileName = Substring(&strImageFileFullName, (&iLastSlashFoundPos + 1), Len(&strImageFileFullName));
&strImageDir = Left(&strImageFileFullName, (&iLastSlashFoundPos - 1));
Else
&strImageFileName = &strImageFileFullName;
&strImageDir = "";
End-If;
&STRLEN = Len(&strImageFileName);
&STRLEN = &STRLEN - 4;
&strImageEmplid = Substring(&strImageFileName, 1, &STRLEN);
If All(&strImageEmplid) Then
PutPhoto();
End-If;
<*delete the files *>
<* &fImage = GetFile(&strImageFileFullName, "E", %FilePath_Absolute);
&fImage.Delete();
&fImage.Close();*>
End-For;
PutPhotoTerm();
End-If;
New feature in 9.1 : Company Directory also publish the photo from PS_EMPL_PHOTO.
Steps to achieve this:
Note:Employee photo are saved with the same emplid.jpg eg. 12345.jpg
Step 1: Create an application engine program with one section with one action =peoplecode
Step 2:Copy paste the below code it will work .
<**************************************************************************************************************************
This function initializes employee photo processing.
It initializes PSOPTIONS.MAXCHUNKSIZE.
The point of the initialization is to select a chunk size that is larger than the largest photo that will be processed.
The processing chunksize is currently set to 1MB. The program would need to be updated if a larger photo is to be loaded.
The original chunksize should be noted as it is possible for the program to abend without restoring the original chunksize
(28K as of this writing).**************************************************************************************************************************>
Function PutPhotoTerm()
If &iOriginalChunkSize < &iPhotoChunkSize Then
SQLExec("UPDATE PSOPTIONS set MAXCHUNKSIZE = :1", &iOriginalChunkSize);
End-If;
MessageBox(0, "", 0, 0, " %1 employee photos committed.", &iPhotoCnt);
CommitWork();
End-Function;
<**************************************************************************************************************************
This function terminates employee photo processing.
It restores PSOPTIONS.MAXCHUNKSIZE to the value that it had when processing began.
The original chunksize should be noted as it is possible for the program to abend without restoring the original chunksize
(28K as of this writing).**************************************************************************************************************************>
Function PutPhotoInit()
SQLExec("SELECT MAXCHUNKSIZE FROM PSOPTIONS", &iOriginalChunkSize);
&iPhotoChunkSize = 1000000;
If &iOriginalChunkSize < &iPhotoChunkSize Then
SQLExec("UPDATE PSOPTIONS set MAXCHUNKSIZE = :1", &iPhotoChunkSize);
End-If;
&recEMPL_PHOTO = CreateRecord(Record.EMPL_PHOTO);
End-Function;
<**************************************************************************************************************************
This function actually loads the photo.
1)The photo file is first loaded to PSFILE_ATTDET using the PutAttachment function.
2)The blob data of the photo is then selected into a variable using SQLExec();
3)The photo file row is then deleted from PSFILE_ATTDET.
4)PS_EMPL_PHOTO.PSIMAGEVER is set to the number of seconds since 01-JAN-2000.
5)The row is is updated or inserted on PS_EMPL_PHOTO depending on whether the employee ID already exists.
6)A commit is performed every 50 rows.**************************************************************************************************************************>
Function PutPhoto()
Local integer &iVersion, &iResult;
Local string &strAttachFileName;
Local string &strMsg;
Local any &anyPhotoBlob;
Local boolean &bFound;
&recEMPL_PHOTO.SetDefault();
&strAttachFileName = &strImageEmplid | ".txt";
&iResult = PutAttachment("record://PSFILE_ATTDET", &strAttachFileName, &strImageFileFullName);
If &iResult <> 0 Then
MessageBox(0, "", 0, 0, "*** Start Message ***");
MessageBox(0, "", 0, 0, "PutAttachement failed");
MessageBox(0, "", 0, 0, "Return Code=%1", &iResult);
MessageBox(0, "", 0, 0, "Image File=%2", &strImageFileFullName);
MessageBox(0, "", 0, 0, "Blob File=%3", &strAttachFileName);
MessageBox(0, "", 0, 0, "*** End Message ***");
CommitWork();
End-If;
SQLExec("SELECT FILE_DATA FROM PSFILE_ATTDET WHERE ATTACHSYSFILENAME = :1 AND VERSION = 1", &strAttachFileName, &anyPhotoBlob);
SQLExec("DELETE FROM PSFILE_ATTDET WHERE ATTACHSYSFILENAME = :1 AND VERSION = 1", &strAttachFileName);
REM MessageBox(0, "", 0, 0, "&strImageEmplid=" &strImageEmplid);
&recEMPL_PHOTO.EMPLID.Value = &strImageEmplid;
&bFound = &recEMPL_PHOTO.SelectByKey();
&recEMPL_PHOTO.EMPLID.Value = &strImageEmplid;
&recEMPL_PHOTO.EMPLOYEE_PHOTO.Value = &anyPhotoBlob;
/* Set the version to seconds from year 2000 */
&recEMPL_PHOTO.PSIMAGEVER.Value = (Days365(Date3(1999, 12, 31), %Date) * 86400) + (%Time - Time3(0, 0, 0));
If &bFound Then
&recEMPL_PHOTO.Update();
Else
&recEMPL_PHOTO.Insert();
End-If;
If Mod(&iPhotoCnt, 50) = 0 Then
MessageBox(0, "", 0, 0, " %1 employee photos committed.", &iPhotoCnt);
CommitWork();
End-If;
End-Function;
<**************************************************************************************************************************
This code drives the program. It
1) Retrieves an array of the filenames in /filepath/pooja/ that have a (.jpg) extension.
2) If no files are found the processing is complete.
3) On the first loop iteration, PutPhotoInit() is called to prepare for images to be inserted.
4) For each file name in the array
a) The array entries contain the full path, e.g., /filepath/pooja/12345.jpg.
The directory is removed leaving only the filename 12345.jpg.
b) For each employee ID the image file is saved to the database by calling PutPhoto();
5) After the loop is complete PutPhotoTerm() is called to reset back to pre-run state.**************************************************************************************************************************>
<* Load list of image file names into array *>
&arrImageFileList = FindFiles("/filepath/pooja/*.jpg", %FilePath_Absolute);
If &arrImageFileList = Null Then
MessageBox(0, "", 0, 0, "No files found");
Else
MessageBox(0, "", 0, 0, "found %1 photo files.", &arrImageFileList.Len);
For &iIdx = 1 To &arrImageFileList.Len
&strImageFileFullName = &arrImageFileList [&iIdx];
&strImageFileName = &strImageFileFullName;
If &iPhotoCnt <= 0 Then
PutPhotoInit();
&iPhotoCnt = 1;
Else
&iPhotoCnt = &iPhotoCnt + 1;
End-If;
MessageBox(0, "", 0, 0, "Processing file %1 %2 :", &iPhotoCnt, &strImageFileFullName);
&strImageEmplid = "";
<* remove the path to extract the simple file name *>
&iStartPos = Find("/", &strImageFileName);
If &iStartPos > 0 Then
&iLastSlashFoundPos = &iStartPos;
&iStartPos = &iStartPos + 1;
Else
&iLastSlashFoundPos = 0;
End-If;
While &iStartPos > 0
&iStartPos = Find("/", &strImageFileName, &iStartPos);
If &iStartPos > 0 Then
&iLastSlashFoundPos = &iStartPos;
&iStartPos = &iStartPos + 1;
Else
Break;
End-If;
End-While;
If &iLastSlashFoundPos > 0 Then
&strImageFileName = Substring(&strImageFileFullName, (&iLastSlashFoundPos + 1), Len(&strImageFileFullName));
&strImageDir = Left(&strImageFileFullName, (&iLastSlashFoundPos - 1));
Else
&strImageFileName = &strImageFileFullName;
&strImageDir = "";
End-If;
&STRLEN = Len(&strImageFileName);
&STRLEN = &STRLEN - 4;
&strImageEmplid = Substring(&strImageFileName, 1, &STRLEN);
If All(&strImageEmplid) Then
PutPhoto();
End-If;
<*delete the files *>
<* &fImage = GetFile(&strImageFileFullName, "E", %FilePath_Absolute);
&fImage.Delete();
&fImage.Close();*>
End-For;
PutPhotoTerm();
End-If;
Subscribe to:
Posts (Atom)