How to Run PS Query Report in Application Engine PeopleCode
Local ApiObject &aRunQry;
&PSQry = %Session.GetQuery();
&qryName = “PS Query Name”;
/* State Record is Prompt field in PS Query*/
&process_instance = PT_TEST_AET.PROCESS_INSTANCE;
If (&PSQry.Open(&qryName, True, True) <> 0) Then
&fileLogLM.WriteLine(“Cannot Open the Query”);
Else
&aQryPromptRec = &PSQry.PromptRecord;
&aQryPromptRec.PROCESS_INSTANCE.Value = &process_instance;
&Date_Format = DateTimeToLocalizedString(%Date, “dd-MMM-yyyy”);
/* Output File */
&strFile = “FILE_” | &process_instance;
/* Use the RunToFile method to execute the Query and return the result to the file specified with Destination.*/
&outStrFile = %FilePath | &strFile;
MessageBox(0, “”, 0, 0, “Query Out File : ” | &outStrFile);
If (&PSQry.RunToFile(&aQryPromptRec, &outStrFile, %Query_XLS, 0) = 0) Then
MessageBox(0, “”, 0, 0, “ResultSet saved into file successfully.”);
Else
MessageBox(0, “”, 0, 0, “Failed to save Resultset into file.”);
End-If;
End-If;