Search code examples
pega

Attach a csv file to work object


I have a XML file which I have to convert in CSV file and then attach in Work-Object?

I already tried by writing an activity and use pxConvertResultsToCSV activity and then try to attach file using Link Object method but by this all the result would come in a single row.


Solution

  • Few steps to be followed...

    1) Parse the XML using activity method Apply-Parse-XML. You will get the XML data in a PageList.

    2) Now create on Rule-Obj-Html rule. In the code part create on table

    <table border="1">    
    <pega:forEach name="YourPageListPage.PageList"> // --> the pagelist in which got the info from xml.
    
    <tr>    
       <TD>
         <pega:reference name="$THIS.COLUMN1"/> // --> property name
      </TD>
      <TD>
         <pega:reference name="$THIS.COLUMN2"/> // --> property name 2
      </TD>
          </tr>
        </pega:forEach>
    </table>
    

    3) Now using Property-Set-HTML get the stream of your html rule in some param variable(for example param.pyFileData) Also create one local variable as strFileData.

    Decode the stream Using Java step. And use this code.

     String atr = (String)tools.getParameterPage().getParameterValue("pyFileData");
    
    byte[] byteArray=(byte[])atr.getBytes();
    
    //encode the byte array into Base64.
     strFileData = Base64Util.encodeToString(byteArray); // strFileData is local variable mentioned in activity.
    

    4) Now create a page of class Data-WorkAttach-File and set following properties on that page.

    .pxRefObjectKey --> pzinskey of work object
    .pxAttachKey    --> any key, maybe current date time
    .pyAttachStream --> your stream which you got from 3rd step (local.strFileData )
    .pyNote         --> any note
    .pxAttachName   --> "filename.csv"
    

    Rest I guess already know.. Save this page using Obj-Save

    5) Use Link-Objects to attach your attachment page to work object.

    Thats it.