Tuesday, June 25, 2013

Pagelets wizard - view attachments

To allow attachments to be shown via a Pagelet generated by the pagelet wizard
1. Create an IScript, e.g. IScript_GetBISDocs, and register it to a hidden portal content reference.
2. Have a query which identifies the information needed. For example, the PS_BIS_DOCS table stores a Source, e.g. PO, and an Doc Key, contains BU, PO number etc.
3. Create a Pagelet using PS Query as a data source, and define a link for one of the columns, e.g. PO ID, which links to the Content Reference created in step 1.
  • Pass in additional parameters as required, e.g. Business Unit and PO ID.

Here is a link to the document in Skydrive with screen shots of the Pagelet, Query etc.
SkyDrive Doc



Here is the PeopleCode from the IScript.

Function IScript_Get_Docs();
   Local string &strBU = %Request.GetParameter("BUSINESS_UNIT");
   Local string &strPO = %Request.GetParameter("PO_ID");
   Local string &DocSys, &DocName, &strPath, &strFile;
   Local integer &intRtrnCd;
   SetTracePC(0);
   SetTraceSQL(0);
   
   rem Fetch the attachments;
   Get_PO_Docs(&strBU | &strPO, 9999, &DocSys, &DocName);
   
   rem SQLExec("SELECT COMMENTS FROM PSURLDEFN WHERE URL_ID=:1", URL.MY_URL, &strPath);
   If Right(GetEnv("PS_FILEDIR"), 1) <> "\" Then;
      &strPath = GetEnv("PS_FILEDIR") | "\";
   Else;
      &strPath = GetEnv("PS_FILEDIR");
   End-If;
   &strFile = &strPath | &DocName;
   &intRtrnCd = GetAttachment(URL.BIS_GL_BUD_FILE_ATTACH, &DocSys, &strFile);
   
   If FileExists(&strFile, %FilePath_Absolute) Then;
      &intRtrnCd = PutAttachment(URL.FILEDB, &DocName, &strFile);
   End-If;
   
   Local Rowset &attachrs;
   Local integer &row_count;
   Local string &attachrec_name = Record.PSFILE_ATTDET;
   Local string &content_type;
   Local string &attachfile_name = &DocName;
   
   
   &attachrs = CreateRowset(@("Record." | Upper(&attachrec_name)));
   &attachrs.Fill("WHERE ATTACHSYSFILENAME = :1 ORDER BY FILE_SEQ", &attachfile_name);
   
   /*Read the file BLOB from database record and write to response*/
   For &row_count = 1 To &attachrs.ActiveRowCount;
      try
         %Response.WriteBinary(&attachrs(&row_count).GetRecord(@("Record." | Upper(&attachrec_name))).FILE_DATA.Value);
      catch Exception &ex
         %Response.SetContentType("text/plain");
         %Response.Write(MsgGetText(137, 182, "Exception in writing binary file data from database" | " " | &ex.ToString()));
      end-try;
   End-For;
   
   /*%Response.SetHeader("Content-Disposition", "attachment;filename=" | EncodeURL(&attachfile_name));*/
   %Response.SetContentType("application/pdf");
   
   SetTracePC(0);
   SetTraceSQL(0);
   
End-Function;

No comments:

Post a Comment