Upload Files in PeopleSoft (File Attachment)

Your rating: None Average: 3.3 (15 votes)

Giving PeopleSoft users the ability to upload files from a page by using the infamous "Browse" button is something that you will most likely do at one point in your PeopleSoft career. As a matter of fact, some questions are popping up on the forum asking for a sample code to get the above requirement accomplished.

I will not be giving any sample code in this post BUT I will show you the way to find the code. Code that is delivered by PeopleSoft and does a little bit more that just uploading a file! The code will show you how to View and Delete uploaded files as well.

Just navigate to PeopleTools > Utilities > Debug > PeopleTools Test Utilities to get the component and page name (Ctrl+J). Open Application Designer and start looking at the code. That same code could be used on your own custom page to allow users to upload, view and delete attachments!

The PeopleTools Test Utilities page is also used to test for Java calls. This is outside the topic of this post, the only section that matters for us on the page is the "File Attachment Test".

/files/peoplesoft-test-utilities-page.png

Please try to help out with unanswered topics on the forum. Chances are you have had the same issue/question some time in your IT career!

Comments

Have a question? Please ask it on the forum instead.
Guest's picture
Guest (not verified)
Re: Upload Files in PeopleSoft (File Attachment)

I have Troubles with this page i opened the "File Attachment Test page but none of the buttons has any peoplecode i tried placing one buttons just like those and didn't work.

Can you help me more please

raj.psoft's picture
User offline. Last seen 1 year 1 day ago. Offline
Joined: 03/25/2010
Posts: 26
Re: Upload Files in PeopleSoft (File Attachment)

You can try out this Code:

Write the code in FieldChange event:

Component string &FileUploaded;
Local string &UPDATE = "Y";

SQLExec("SELECT ATTACHSYSFILENAME FROM %table(CSGC_CSHT_ATACH) WHERE LASTUPDOPRID = :1", %OperatorId, &OldFileName); /* Get the previous file name */
&RETCODE = AddAttachment("RECORD://CSGC_CSHT_ATACH", &ATTACHSYSFILENAME, "", &ATTACHUSERFILE, 0);

Evaluate &RETCODE
When = 0 /* Returns Zero, when user clicks on OK with the valid File Path */
/* Then Check whether the file is only .txt file or not, if not throw an error msg and delete the file */
If Lower(Right(&ATTACHUSERFILE, 4)) <> ".txt" Then
MessageBox(0, "", 27333, 44, ""); /* You can only upload .txt files. */
&RETCODE1 = DeleteAttachment("RECORD://CSGC_CSHT_ATACH", &ATTACHUSERFILE); /* Delete file */
&FileUploaded = "N";
&UPDATE = "N";
End-If;

SQLExec("SELECT COUNT(1) FROM %table(CSGC_CSHT_ATACH) WHERE LASTUPDOPRID = :1", %OperatorId, &Count); /* Check whether any rows are there in Attachment Record or not */

If &Count > 1 Then /* means more than one record is existing, So Delete the previous file */
&RETCODE2 = DeleteAttachment("RECORD://CSGC_CSHT_ATACH", &OldFileName); /* Delete file */
End-If;

If &UPDATE = "Y" Then
&UpdatedFileName = %OperatorId | "_" | &ATTACHUSERFILE;
SQLExec("UPDATE %table(CSGC_CSHT_ATACH) SET ATTACHSYSFILENAME = :1 WHERE LASTUPDOPRID = :2", &UpdatedFileName, %OperatorId);
&FileUploaded = "Y";
End-If;

Break;
When = 11 /* Returns 11, when user clicks on OK without File Path */
When = 2 /* Returns 2, when user clicks on CANCEL Button */
MessageBox(0, "", 27333, 67, ""); /* Please Specify the path and upload again. */
&FileUploaded = "N";
Break;
End-Evaluate;

Raj

pramod's picture
pramod (not verified)
Re: Upload Files in PeopleSoft (File Attachment)

I am getting the below error while attaching a file. Please help.

CAN NOT LOCATE DESTINATION SYSTEM

samar's picture
samar (not verified)
Re: Upload Files in PeopleSoft (File Attachment)

Hello everyone,
I am, able to add the attachment from the below code but am not able to view the file ... can anyone suggest me on this....
Declare Function add_attachment PeopleCode FILE_ATTACH_WRK.ATTACHADD FieldChange;
Declare Function display_attachment_buttons PeopleCode FILE_ATTACH_WRK.ATTACHADD RowInit;

Local number &CurRow, &RETCODE;
Local string &Guid, &URL_ID;

/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
/* Call the correct database record where your file attachment */
/* will be stored */
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
&URL_ID = "URL.N_LOCATION_TBL";

/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
/* In order to make sure the attachmentname is unique */
/* you can add a GUID in front of your File name */
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
&Guid = UuidGenBase64();

add_attachment(@&URL_ID, "", &Guid, 0, True, "Record.N_LOCATION_TBL", N_LOCATION_TBL.ATTACHSYSFILENAME, N_LOCATION_TBL.ATTACHUSERFILE, 2, &RETCODE);
WinMessage("&RETCODE" | &RETCODE, 0);
If &RETCODE = %Attachment_Success Then
display_attachment_buttons(N_LOCATION_TBL.ATTACHUSERFILE);
WinMessage("Attachment Uploaded");
DoSaveNow();
End-If;

Hari_aindian's picture
User offline. Last seen 5 years 26 weeks ago. Offline
Joined: 08/02/2010
Posts: 84
Re: Upload Files in PeopleSoft (File Attachment)

You need to use ViewAttachment function to view the uploaded file.

Regards,
Hari.A

meg's picture
meg (not verified)
Re: Upload Files in PeopleSoft (File Attachment)

Hello,

Can you please help me to solve this error when adding attachment in the page? The below error is prompting when I am attempting to attach the file. Thanks!
"AddAttachment failed (137,2)
The AddAttachment() call failed. "

CODE:
Declare Function add_attachment PeopleCode FILE_ATTACH_WRK.ATTACHADD FieldChange;
Declare Function display_attachment_buttons PeopleCode FILE_ATTACH_WRK.ATTACHADD RowInit;

Local number &CurRow, &RETCODE;
Local string &Guid, &URL_ID;

&URL_ID = "URL.RECEIPTS";

&Guid = UuidGenBase64();

add_attachment(@&URL_ID, "", &Guid, 0, True, "Record.CSAA_EX_ATTACH", CSAA_EX_ATTACH.ATTACHSYSFILENAME, CSAA_EX_ATTACH.ATTACHUSERFILE, 2, &RETCODE);

If &RETCODE = %Attachment_Success Then
display_attachment_buttons(CSAA_EX_ATTACH.ATTACHUSERFILE);
DoSaveNow();
End-If;

meg's picture
meg (not verified)
Re: Upload Files in PeopleSoft (File Attachment)

Helo,

How can attchment be blank evrytime that the user is activating the page again to create attachment? The history attached file by the user is still there. Thanks!

meg's picture
meg (not verified)
Re: Upload Files in PeopleSoft (File Attachment)

This is now workking. I already solved the error.

PsoftGuy's picture
PsoftGuy (not verified)
Re: Upload Files in PeopleSoft (File Attachment)

How did you resolve the error?
Can you please share, since this forum works best when we all exchange solutions and ideas.

Thanks!

Guest's picture
Guest (not verified)
Re: Upload Files in PeopleSoft (File Attachment)

Does anyone know of a way to allow a user to upload an image file and also capture the file, rename it and move it to shared directory? I can accomplish it by using the InsertImage(), AddAttachment() and PutAttachment() functions, but it requires the user to 'upload' the file twice. We're trying to allow a third party application to view the uploaded images which are stored in the INV_ITEM_PHOTO record, by sending the application a full url path to the item image file in a shared directory.

Guest's picture
Guest (not verified)
Re: Upload Files in PeopleSoft (File Attachment)

I have out in the component PostBuild event a scrollflush function.

Guest's picture
Guest (not verified)
Re: Upload Files in PeopleSoft (File Attachment)

i am looking for a code that can check the originality of the file (that means if the file is renamed , then it should not be allowed to be uploaded in a browser)
if any one could suggest ...

Rich M's picture
Rich M (not verified)
Re: Upload Files in PeopleSoft (File Attachment)

Hello,
I was able to apply this code to send an attachment to our server, and also to retrieve (view) a file. But something is happening to the files when I return them from the server to view them. For example, I tried to save a text file, but when I view the file it appears that all the carriage returns have been removed. A file saved like this:
-- Script : delete_bad_referral.sql
--
-- 01/10/2011 rjm
--
-- Return failure code when program does not complete successfully
whenever sqlerror exit failure;
whenever oserror exit failure;

Comes back looking like this:
-- Script : delete_bad_referral.sql -- -- 01/10/2011 rjm -- -- Return failure code when program does not complete successfully whenever sqlerror exit failure; whenever oserror exit failure; set echo on set feedback on set head off set linesize 500 --select select * FROM sysadm

Has anyone seen this before? Know how to correct it?

Harry's picture
Harry (not verified)
Re: Upload Files in PeopleSoft (File Attachment)

Hi All,
I am facing the issue with file upload.
we have two
either we can you URL.yourURL ID or FTP://YourFTPUser:YourFTPPassword@YourComputerName/YourDirectoryPath

when i am using the URL.yourURL then files is uploaded sucessfully. but when i am using the FTP command then it's not working . i want both the option to be work .can somebody help me here

Guest's picture
Guest (not verified)
Re: Upload Files in PeopleSoft (File Attachment)

Hi All,

Need to upload some files to https location using AddAttachment function. I created a URL definition for that https path and used that in Addattachment function. But it is throwing the following error during uploading of files.
AddAttachment() call failed.
Message not found
please help

Guest's picture
Guest
Re: Upload Files in PeopleSoft (File Attachment)

The AddAttachment function limits the user to files with names no longer than 64 characters long. I have a user thatinsists they must use longer file names when uploading the file into our system. Unfortunately, there is no way to reconfigure the AddAttachment parameters to allow for a longer file name. How can I just display the same windows open file dialog pop-up dialog (as is displayed using AddAttachment) and then manipulate the file behind the scenes? Or can I trick the AddAttachment to return the file name even if it is too long?

Guest's picture
Guest
Re: Upload Files in PeopleSoft (File Attachment)

Look like there are no ways to manipulate that unfortunately as that was the way PeopleSoft has written the function, and we cannot extend that (like other languages). The only thing you can do is display a text on the page and let users to upload a file which has max 64 chars in the file name

Janaka11's picture
User offline. Last seen 3 years 32 weeks ago. Offline
Joined: 03/01/2015
Posts: 5
Re: Upload Files in PeopleSoft (File Attachment)
Guest's picture
Guest
Re: Upload Files in PeopleSoft (File Attachment)I

I am getting error Add attachment failed 137,2. When I looked at trace log, it shows "failed to get table name for record PS_ENRL_FILE". I created this custom record to store the attached files by using sub record FILE_ATTDET_SBR.
Interesting this is If I use delivered record to PSFILE_ATTDET to store file it works...

Please help.

Guest's picture
Guest
Re: Upload Files in PeopleSoft (File Attachment)

Can you let us know how you solved this error please?

Guest's picture
Guest
Re: Upload Files in PeopleSoft (File Attachment)

When I open a file with viewattachment then file is displaying in new browser window. In New browser window, back button is displaying in the browser. When i Click on that button, system is showing '404 not found' error.

Is there any way to hide/disable back button on the browser when file opens in the browser .

Guest's picture
Guest
Re: Upload Files in PeopleSoft (File Attachment)

Dude,

Check in View Record PeopleCode... You will get...