Running a Connected Query in Preview Mode or Background Mode
In preview mode, the connected query is run immediately on the application sever. The output data is displayed in a separate browser window. In preview mode, the Prompts parameter is required; the runProcessInfo parameter must be set to Null. The Prompts parameter should be retrieved using the QueriesPromptsArray property. If this array length is greater than 0, this array must be populated.
Similar to preview mode, running a connected query in background mode results in the output data being displayed in a separate browser window. However, in background mode, the connected query is run through Process Scheduler with a REN server. Running a connected query in this manner prevents blocking on the application server. While the report file is generated, the user can continue working with the PeopleSoft application.
In the following example, assume that an application calls the RunConnectedQuery function with all required parameters. The function returns an error string if any error occurs.
import PT_CONQRS:CONQRSMGR;
import PT_CONQRS:QUERYITEMPROMPT;
Function ShowException(&errString As Exception);
/* Perform exception processing */
End-Function;
Function RunConnectedQuery(&sOprId As string, &sCONQRSNAME As string, &RunMode ⇒
As number) Returns string
Local boolean &result;
Local array of PT_CONQRS:QUERYITEMPROMPT &aPrompts;
Local string &str;
Local number &processID;
Local boolean &IsChangeDB, &IsNewCnt;
Local PT_CONQRS:CONQRSMGR &cConQrsInst;
/* While working with connected queries, it is recommended to use a try- */
/* catch block */
try
/* Create and open an object. System tries to find a connected query */
/* with private ownership first for current user. If not found, it */
/* uses a public ownership */
&cConQrsInst = create PT_CONQRS:CONQRSMGR("", &sCONQRSNAME);
&result = &cConQrsInst.Open(&cConQrsInst.Const.InitExisting);
/* Check for errors */
&str = &cConQrsInst.ErrString;
If &str <> "" Then
Error &cConQrsInst.ErrString;
End-If;
/* Validate the previously opened connected query object */
If Not &cConQrsInst.Validate() Then
&str = &cConQrsInst.ErrString;
If &str <> "" Then
Error &cConQrsInst.ErrString;
End-If;
End-If;
/* Preview Mode- AppServer execution */
/* Populate prompts. NOTE: It is required for 'interactive' execution */
/* using an application server. In the case of scheduled execution, */
/* prompts are read from the database */
If &RunMode = &cConQrsInst.Const.RunMode_Prev Then
&aPrompts = FillQueriesPrompts();
If None(&aPrompts) Then
/* User hit Cancel on a Prompt dialog */
&cConQrsInst.ResetQueriesPrompt();
Return &cErrIndicator;
End-If;
/* Restrict number of rows being displayed for each member query. */
/* If user does not set this value, the default number is used */
If All(PSCONQRS_WRK.QRY_MAX_FETCH) Then
&cConQrsInst.MaxRowsPerQuery = &numRows;
Else
&cConQrsInst.MaxRowsPerQuery = &cConQrsInst.Const.⇒
RunMode_Prev_DefRowNumber;
End-If;
/* Run the connected query. NOTE: The runProcessInfo parameter is Null */
&result = &cConQrsInst.Run(&aPrompts, Null);
End-If; /* end of Mode selection */
/* ‘Run to Window’ mode */
If &RunMode = &cConQrsInst.Const.RunMode_Window Then
&IsChangeDB = True;
&IsNewCnt = False;
/* You are required to set run control parameters for immediate */
/* execution using Process Scheduler */
&result = &cConQrsInst.SetRunControlData(&cConQrsInst.Const.⇒
RunCntlId_Auto, &IsNewCnt, &IsChangeDB);
If &result Then
&processID = &cConQrsInst.RunToWindow();
If All(&processID) Then
&result = True;;
End-If;
End-If;
End-If; /* end of Mode selection */
/* Check for errors */
&str = &cConQrsInst.ErrString;
If &str <> "" Then
Error &cConQrsInst.ErrString;
End-If;
Return &str;
catch Exception &Err
ShowException(&Err);
end-try;
End-Function;