3 Replies Latest reply: Apr 19, 2014 12:35 AM by Pars RSS

    Save the contents of the form elements in  a txt file

    JJIN


      Hi,

       

      I am trying to save the contents of the form as a text file on clicking a button. For example in my form i have 4 textboxes

       

      1.Customer id

      2.Customer location

      3.Customer last name

      4.Customer first name

       

      There is a save button in the page. Once i click on the save button, i need to get a download prompt to save the file(a txt file). The txt file must contain the values of fields in each line. Can we achieve this using Apex?

       

      Thanks,

      TJ

        • 1. Re: Save the contents of the form elements in  a txt file
          carlos.pereira

          Hi TJ,

           

          Yes, its possible. For that you have to use a bit of PL/SQL Code.

           

          In the page you are going to create a Branch;

          Branch Point=On Submit: After Processing (After Computation, Validation, and Processing);

          Branch Type=Branch to PL/SQL procedure

           

           

          And the branch code you need to have something like this:

           

           

          declare

            v_clob clob;

            v_blob blob;

            dest_offset NUMBER  := 1;

            src_offset  NUMBER  := 1;

            amount      INTEGER := dbms_lob.lobmaxsize;

            blob_csid   NUMBER  := dbms_lob.default_csid;

            lang_ctx    INTEGER := dbms_lob.default_lang_ctx;

            warning     INTEGER;

            v_length NUMBER  ;

          begin

           

            dbms_lob.createtemporary(v_clob, true);

            dbms_lob.createtemporary(v_blob, true);

            

            v_clob := 'ID: '||:PXX_ID ||'

          Location:   '||:PXX_LOCATION||'

          Last Name:  '||:PXX_LAST_NAME||'

          First Name: '||:PXX_FIRST_NAME;

           

            DBMS_LOB.CONVERTTOBLOB(

              v_blob,

              v_clob,

              amount,

              dest_offset,

              src_offset,

              blob_csid,

              lang_ctx,

              warning);

             

            v_length := dbms_lob.GETLENGTH(v_blob);

            --

            -- set up HTTP header

            --

            owa_util.mime_header('application/octet', FALSE );

           

           

            -- set the size so the browser knows how much to download

            htp.p('Content-length: ' || v_length);

            -- the filename will be used by the browser if the users does a save as

            htp.p('Content-Disposition:  attachment; filename="download.txt"');

            -- close the headers          

            owa_util.http_header_close;

            -- download the BLOB

            wpg_docload.download_file( v_blob );

           

           

          end;

           

          Cheers

           

          Carlos Pereira

          • 2. Re: Save the contents of the form elements in  a txt file
            JJIN

            Thanks Carlos. It is working . But i am trying to add a new line between the entries. Now the output i am gettting as

             

            ID: 3 Location:   ewe Last Name:  sds First Name: sdxs.

             

            I want to get each item in a new line, like

             

            ID: 3
            Location:   ewe

            Last Name:  sds

            First Name: sdxs

             

            I tried /n and chr(10) but giving errors.how can we add a newline in the clob field.

             

            v_clob := 'ID: '||:PXX_ID ||' 

            Location:   '||:PXX_LOCATION||'

            Last Name:  '||:PXX_LAST_NAME||'

            First Name: '||:PXX_FIRST_NAME;

             

             

             


            • 3. Re: Save the contents of the form elements in  a txt file
              Pars

              719275 wrote:

               

              Thanks Carlos. It is working . But i am trying to add a new line between the entries. Now the output i am gettting as

               

              ID: 3 Location:   ewe Last Name:  sds First Name: sdxs.

               

              I want to get each item in a new line, like

               

              ID: 3
              Location:   ewe

              Last Name:  sds

              First Name: sdxs

               

              I tried /n and chr(10) but giving errors.how can we add a newline in the clob field.

               

              v_clob := 'ID: '||:PXX_ID ||'

              Location:   '||:PXX_LOCATION||'

              Last Name:  '||:PXX_LAST_NAME||'

              First Name: '||:PXX_FIRST_NAME;

               

               

               

               

              add chr(13)||chr(10) after each line means your code like as follows

              v_clob := 'ID: '||:PXX_ID ||chr(13)||chr(10)||' 
              Location:   '||:PXX_LOCATION||chr(13)||chr(10)||'
              Last Name:  '||:PXX_LAST_NAME||chr(13)||chr(10)||'
              First Name: '||:PXX_FIRST_NAME;
              
              

              hope this helps.....