Thursday, December 23, 2010

File Attachments


File Attachments Overview:
To achieve this functionality we need following records
Delivered Records:
FILE_ATTACH_WRK:              Contains the delivered code to create attachments
FILE_ATTDET_SBR:                 Is saved as another record (FTP record (any SQL record)) ex: TEST_FTP
Created Records:
Transaction record (Ex: TEST_TRANS): This record holds the key fields along with ATTACHSYSFILENAME and ATTACHUSERFILE fields into this record.
FTP record (Ex: TEST_FTP): This record will hold the attachment.  This record will contain only the sub-record FILE_ATTDET_SBRNo other fields can be placed on this record or the delivered process will not work.
Process:
  1. Build the records:
  • Create a new record that has only the sub record of FILE_ATTDET_SBR in it.  No other fields can be added to this record.( Ex: TEST_FTP)
  • Create a new record (Ex: TEST_TRANS) that has key fields .
  • Create the new tables at the database level.
  1. Create the page:
  • Create the page according to the requirement and use the field from the record FILE_ATTACH_WRK for attachment buttons/links.
  • TEST_TRANS.ATTACHUSERFILE(FileName) DisplayOnly.
  • All other columns from TEST_TRANS are Invisible.
  • Fields from FILE_ATTACH_WRK (ATTACHADD, ATTACHVIEW, and ATTACHDELETE) are pushbuttons.
  • TEST_FTP is not added to this page or any page
  1. Create Component
  2. Add a new URL definition Online:


    Note: This is not necessary if you are storing to the Database, since it is highly unlikely you will switch the record that the file attachments will be inserted into. If storing on a file server, you should create a URL definition since server names can change.
    1. Browse to Main Menu > PeopleTools > Utilities > URLs.
    2. Add a new URL (i.e. DEMO_URL).
    The URL, when inserting the file into the database, but be the record that will be storing the File Attachment.
    The text must be in the format of:
                   Storing to Database:             record://TEST_FTP
                   Storing on File Server:         http://myserverpath.com/whatever
                                                                        ftp://my_ftp_server/path
    Save the URL definition

     
  3. Add Peoplecode
  • RowInit: You will need to determine the rules behind enabling or disabling the pushbuttons. There is delivered function on FILE_ATTACH_WRK.ATTACHADD. RowInit that can be called or you can add own logic.
        (Can call in component PeopleCode <COMPONENT>.FILE_ATTACH_WRK.RowInit).
  • Add the following code to the component record field PeopleCode <COMPONENT>.FILE_ATTACH_WRK.ATTACHADD.FieldChange


    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.DEMO_URL";


    /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
    /* 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.TEST_TRANS", TEST_TRANS.ATTACHSYSFILENAME,
    TEST_TRANS.ATTACHUSERFILE, 2, &RETCODE);


    If &RETCODE = %Attachment_Success Then
    display_attachment_buttons();
    DoSaveNow();
    End-If;
  • Add the following code to the component record field PeopleCode <COMPONENT>.FILE_ATTACH_WRK. ATTACHVIEW.FieldChange

    Declare Function view_attachment PeopleCode FILE_ATTACH_WRK.ATTACHVIEW FieldChange;
    Declare Function display_attachment_buttons PeopleCode FILE_ATTACH_WRK.ATTACHADD RowInit;

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

    view_attachment(@&URL_ID, TEST_TRANS.ATTACHSYSFILENAME, TEST_TRANS.ATTACHUSERFILE, 2, &RETCODE);

    If &RETCODE = %Attachment_Success Then
    display_attachment_buttons();
    DoSaveNow();
    End-If;
  • Add the following code to the component record field PeopleCode <COMPONENT>.FILE_ATTACH_WRK. ATTACHDELETE.FieldChange

    Declare Function delete_attachment PeopleCode FILE_ATTACH_WRK.ATTACHDELETE FieldChange;
    Declare Function display_attachment_buttons PeopleCode FILE_ATTACH_WRK.ATTACHADD RowInit;

    Local number &Ret;
    Local String &URL_ID;

    &Ret = MessageBox(%MsgStyle_YesNo, "", 0, 0, "Are you sure you would like to delete the attachment?");
    If &Ret = %MsgResult_Yes Then
    /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
    /* Call the correct database record where your file attachment */
    /* will be stored */
    /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
    &URL_ID = "URL.DEMO_URL";

    delete_attachment(@&URL_ID, TEST_TRANS.ATTACHSYSFILENAME, TEST_TRANS.ATTACHUSERFILE, 2, &RETCODE);

    If &RETCODE = %Attachment_Success Then
    display_attachment_buttons();
    DoSaveNow();
    End-If;
    End-If;
  • Add the following code to the component record PeopleCode <COMPONENT>.<Record>.<FirstKey>.SaveEdit

    /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
    /* This code is necessary so that when an attachment is deleted */
    /* the now empty row can be deleted from the database */
    /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
    Local number &Rs_Count, &i;
    Local Rowset &Rs;

    &Rs = GetLevel0()(1).GetRowset(Scroll.TEST_TRANS);
    &Rs_Count = &Rs.ActiveRowCount;
    For &i = &Rs_Count To 1 Step - 1
    If None(&Rs(&i).TEST_TRNS.ATTACHSYSFILENAME.Value) Then
    &Rs.DeleteRow(&i);
    End-If;
    End-For;
NOTE:
SYNTAX: AddAttachment(URLDestination,
DirAndFileName,
FileType,
UserFile[, MaxSize [, PreserveCase[, UploadPageTitle[, AllowLargeChunks]]]] )
PreserveCaseSpecify a Boolean value to indicate whether the case of the extension of the specified file is preserved or not; True, preserve the case, False, convert the file name extension to all lowercase letters.
The default value is False.
Warning! If you use the PreserveCase parameter, it is important that you use it in a consistent manner with all the relevant file-processing functions or you may encounter unexpected file-not-found errors.
NOTE: Configuring the Web Server to Support Additional MIME Types

Web Server
Location of Deployment Copy
WebLogicPS_HOME/webserv/web_server/applications/peoplesoft/PORTAL.war/WEB-INF/web.xml
WebSpherePS_HOME/webserv/profile_name/installedApps/app_nameNodeCell/app_name.ear/PORTAL.war/WEB-INF/web.xml
You must restart your web server before these changes are recognized.

2 comments:

Unknown said...

Hi Pawan, How to read TEST_FTP file data to split(',' seperated) and insert into another table?

photo said...

https://techdialouge.blogspot.com/2017/12/peoplesoft-write-data-from-record-to.html

Post a Comment