Wednesday, July 29, 2015



PeopleCode to Generate BI Publisher report using PeopleSoft Connected Queries



import PSXP_RPTDEFNMANAGER:*;
import EP_FUNCTIONS:EP_Utilities2;
import PT_CONQRS:*;

Declare Function DeleteLocalFile PeopleCode PSXPFUNCLIB.FUNCLIB FieldFormula;
Declare Function GetDirSeparator PeopleCode PSXPFUNCLIB.FUNCLIB FieldFormula;

Function ShowReport(&sEmplID As string, &nAppraisalID As number)
  
   try
     
      Local PT_CONQRS:CONQRSMGR &oConQrsInst;
      Local array of PT_CONQRS:QUERYITEMPROMPT &CQPromptsArray;
      Local string &sRep$ortName, &Template, &sDirSep, &ServerPrefix, &OutStr, &LanguageCd;
      &sReportName = "XYZ_SP_XMLP";
      &Template = "XYZ_SP_XMLP_1";
      &LanguageCd = %Language_User;
     
      /* detect system directory separator */
      &sDirSep = GetDirSeparator();
      /* create process directory */
      CreateDirectory("XMLP", %FilePath_Relative);
     
      /* create report defn object */
      &oRptDefn = create PSXP_RPTDEFNMANAGER:ReportDefn(&sReportName);
      &oRptDefn.Get();
     
      /* output directory */
      &RptOutputDir = GetEnv("PS_SERVDIR") | &sDirSep | "files" | &sDirSep | "XMLP" | &sDirSep | UuidGen();
      &sOutputDir = &RptOutputDir | &sDirSep | "RptInst";
      &sDataDir = &RptOutputDir | &sDirSep | "Data";
      CreateDirectory(&sOutputDir, %FilePath_Absolute);
      CreateDirectory(&sDataDir, %FilePath_Absolute);
     
      &oRptDefn.OutDestination = &RptOutputDir;
     
      /*Create a location to place the connected query output file*/
      &CQXmlFile = GetFile(&RptOutputDir | &sDirSep | "XYZ_CQData.xml", "N", "UTF8", %FilePath_Absolute);
     
      /* get a reference to the Connected Query defn object */
      &oConQrsInst = create PT_CONQRS:CONQRSMGR("", "XYZ_SP_XMLP_CONQRY"); /*The blank "" parameter is filled in with OPRID if this is a private CQ. */
      &result = &oConQrsInst.Open(&oConQrsInst.Const.InitExisting);
      &CQPromptsArray = &oConQrsInst.QueriesPromptsArray;
     
      /*Loop through the Connected Query "Queries" and fill in each query's prompts as needed*/
      For &ap = 1 To &CQPromptsArray.Len
         &CQPromptRec = &CQPromptsArray.Get(&ap).QueryPromptRecord;
         &CQPromptRec.GetField(1).Value = &sEmplID;
         /* Start: 01.04.2014: Narvinder Singh */
         &CQPromptRec.GetField(2).Value = &nAppraisalID;
         /* end: 01.04.2014: Narvinder Singh */
      End-For;
     
      &OutStr = &oConQrsInst.RunToXMLFormattedString(&CQPromptsArray);
     
      /*The following 2 lines of code for formatting issues caused by extra carriage returns.  */
      &OutStr = Substitute(&OutStr, ">" | Char(13) | "~", ">");
      &OutStr = Substitute(&OutStr, ">" | Char(10) | "~", ">");
     
     
      /*Write the output to the xml file for use in the XML Publisher report*/
      &CQXmlFile.WriteLine(&OutStr);
      &CQXmlFile.Close();
      &oRptDefn.SetRuntimeDataXMLFile(&RptOutputDir | &sDirSep | "XYZ_CQData.xml"); /*Set XMLP report to use this file*/
     
      &oRptDefn.ProcessReport(&Template, &LanguageCd, %Date, "");
      CommitWork();
     
         
      /* cleanup your temp files to keep the application server clean*/
      RemoveDirectory(&RptOutputDir, %FilePath_Absolute + %Remove_Subtree);
     
     
   catch Exception &Err
      Local string &sSub1, &sSub2, &sSub3, &sSub4, &sSub5;
      Evaluate &Err.SubstitutionCount
      When > 4
         &sSub5 = &Err.GetSubstitution(5);
      When > 3
         &sSub4 = &Err.GetSubstitution(4);
      When > 2
         &sSub3 = &Err.GetSubstitution(3);
      When > 1
         &sSub2 = &Err.GetSubstitution(2);
      When > 0
         &sSub1 = &Err.GetSubstitution(1);
      End-Evaluate;
      Error MsgGet(&Err.MessageSetNumber, &Err.MessageNumber, &Err.ToString(), &sSub1, &sSub2, &sSub3, &sSub4, &sSub5);
   end-try;
  
  
End-Function;

No comments:

Post a Comment