Diagnostic Plug-In Examples

The following are examples of typical actions found in diagnostic plug-ins.

The following example demonstrates how to retrieve record output and display it. In this case, the plug-in retrieves the list of languages from the database.

import PT_DIAGNOSTICS:*;

class GetLanguages extends PTDiagnostics
   /* Constructor */
   
   method GetLanguages();
   
   /* Public Method */
   method GetDiagnosticInfo();
   method IsPlugIn();
   
private
   
end-class;

method GetLanguages;
   Local boolean &status;
   %Super = create PTDiagnostics();
   &status = %Super.SetProperty(%This, "hasRowset", "Boolean", True);
   &status = %Super.SetProperty(%This, "Purpose", "String",
 "This is a diagnostic to determine all of the languages
 installed in your PeopleSoft Database.");
end-method;

method GetDiagnosticInfo
   Local boolean &stat;
   Local number &rc1;
   Local Rowset &rs1;
   Local string &sError;
   
   &rs1 = CreateRowset(Record.PSLANGUAGES);
   &rc1 = &rs1.Fill();
   &stat = %Super.InsertData("Rowset", "LANGUAGES description,
 not used in output", &rs1);
   
end-method;

method IsPlugIn
end-method;

This example demonstrates how to retrieve string-based output and display it. In this case, the plug-in retrieves the license code.

import PT_DIAGNOSTICS:*;

class GetLicenseCode extends PTDiagnostics
   /* Constructor */
   
   method GetLicenseCode();
   
   /* Public Method */
   method GetDiagnosticInfo();
   method IsPlugIn();
   
private
   
end-class;

method GetLicenseCode;
   Local boolean &status;
   Local string &sError;
   %Super = create PTDiagnostics();
   &status = %Super.SetProperty(%This, "Purpose", "String",
 "This is a diagnostic to determine your license code");
end-method;

method GetDiagnosticInfo
   Local string &sLicenseCode, &sLicenseGroup;
   Local boolean &status;
   Local string &sError;
   
   SQLExec("SELECT LICENSE_CODE, LICENSE_GROUP FROM PSOPTIONS",
 &sLicenseCode, &sLicenseGroup);
   &status = %Super.InsertData("String",
 "Your License Code is: ", Upper(&sLicenseCode));
   
end-method;

method IsPlugIn
end-method;

This example demonstrates how to retrieve a Number type output and display it. In this case, we retrieve the number of rows from the PSRECDEFN based on different conditions.

import PT_DIAGNOSTICS:*;

class GetPSRECDEFNCount extends PTDiagnostics
   /* Constructor */
   
   method GetPSRECDEFNCount();
   
   /* Public Method */
   method GetDiagnosticInfo();
   method IsPlugIn();
   
private
   
end-class;

method GetPSRECDEFNCount;
   Local boolean &status;
   Local string &sError;
   %Super = create PTDiagnostics();
   &status = %Super.SetProperty(%This, "Purpose", "String",
 "This is a diagnostic to count the number of records, views,
 derived work records, and sub-records in your PeopleSoft Database.");
end-method;

method GetDiagnosticInfo
   Local boolean &status;
   Local number &rc1;
   Local Rowset &rs1;
   Local string &sError;
   
   &rs1 = CreateRowset(Record.PSRECDEFN);
   &rc1 = &rs1.Fill("where RECTYPE = 0");
   &status = %Super.InsertData("Number",
 "Number of Records: ", &rs1.RowCount);
   
   &rs1 = CreateRowset(Record.PSRECDEFN);
   &rc1 = &rs1.Fill("where RECTYPE = 1");
   &status = %Super.InsertData("Number",
 "Number of Views: ", &rs1.RowCount);
   
   &rs1 = CreateRowset(Record.PSRECDEFN);
   &rc1 = &rs1.Fill("where RECTYPE = 2");
   &status = %Super.InsertData("Number",
 "Number of Derived/Work Records: ", &rs1.RowCount);
   
   &rs1 = CreateRowset(Record.PSRECDEFN);
   &rc1 = &rs1.Fill("where RECTYPE = 3");
   &status = %Super.InsertData("Number",
 "Number of sub-records: ", &rs1.RowCount);
   
end-method;

method IsPlugIn
end-method;

This example demonstrates how to use global prompting. This example includes the use of these constructs:

  • GetDynamicPrompt (): This function prompts for the input.

  • InsertQuestion (): Inserts a question.

  • GetUserInputByKey (): Gathers the input.

In this example, the plug-in retrieves the number of rows from the PSRECDEFN based on different records. The search record is usually retrieved from the user during runtime.

import PT_DIAGNOSTICS:*;

class GetRecFieldsBeginningWith extends PTDiagnostics
   /* Constructor */
   method GetRecFieldsBeginningWith();
   
   /* Public Method */
   method GetDiagnosticInfo();
   method GetDynamicPrompt();
   method IsPlugIn();
private
   
end-class;

method GetRecFieldsBeginningWith;
   Local boolean &status;
   %Super = create PTDiagnostics();
   &status = %Super.SetProperty(%This, "Where", "Boolean", True);
   &status = %Super.SetProperty(%This, "Purpose", "String",
 "This is a diagnostic to print out a listing of fields from records
 in your PeopleSoft database that matches search criteria.
 This diagnostic tests globalType and classType prompting.
 The global prompt is retrieved from inputs defined by
 a different class in this plug-in.");
end-method;

method GetDynamicPrompt
   Local boolean &status;
   Local string &sError;
   
   /* define prompt for this class */
   &status = %Super.InsertQuestion("Flds", "Enter FieldNames to retrieve,
 beginning with:", "String", False);
end-method;

method GetDiagnosticInfo
   Local boolean &status;
   Local string &sValRecs, &sValFlds, &sError;
   Local number &iCount = 0;
   Local Record &REC;
   Local boolean &bReturn;
   Local SQL &SQL1;
   
   &REC = CreateRecord(Record.PSRECFIELD);
   &SQL1 = CreateSQL("%SelectAll(:1)
 where RECNAME LIKE :2 and FIELDNAME LIKE :3");
   
 /* get global prompt */
   &status = %Super.GetUserInputByKey("Recs", &sValRecs);
 /* get class prompt */
   &status = %Super.GetUserInputByKey("Flds", &sValFlds);
   &SQL1.Execute(&REC, Upper(&sValRecs | "%"), Upper(&sValFlds | "%"));
   While &SQL1.Fetch(&REC)
      &iCount = &iCount + 1;
      &status = %Super.InsertData("String",
 "Record: " | &REC.RECNAME.Value | " has the following field
 that matches your criteria: ", &REC.FIELDNAME.Value);
   End-While;
   
end-method;

method IsPlugIn
end-method;

The following example demonstrates the use of global and class-level prompts.

import PT_DIAGNOSTICS:*;

class GetRecFieldsBeginningWith extends PT_DIAGNOSTICS:PTDiagnostics
   /* Constructor */
   method GetRecFieldsBeginningWith();
   
   /* Public Method */
   method GetDiagnosticInfo();
   method GetDynamicPrompt();
   method IsPlugIn();
private
   
end-class;

method GetRecFieldsBeginningWith;
   Local boolean &status;
   %Super = create PT_DIAGNOSTICS:PTDiagnostics();
   &status = %Super.SetProperty(%This, "Where", "Boolean", True);
   &status = %Super.SetProperty(%This, "Purpose", "String", "This is a diagnostic
 to print out a listing of fields from records in your PeopleSoft database that
 matches search criteria. This diagnostic tests globalType and classType
 prompting. The global prompt is retrieved from inputs defined by a different
 class in this plug-in.");
end-method;

method GetDynamicPrompt
   Local boolean &status;
   Local string &sError;
   
   /* define the global prompt*/
   &status = %Super.InsertQuestion("Recs", "Enter RecordNames to retrieve,
 beginning with:", "String", True);
   
   /* define prompt for this class */
   &status = %Super.InsertQuestion("Flds", "Enter FieldNames to retrieve,
 beginning with:", "String", False);
end-method;

method GetDiagnosticInfo
   Local boolean &status;
   Local string &sValRecs, &sValFlds, &sError;
   Local number &iCount = 0;
   Local Record &REC;
   Local boolean &bReturn;
   Local SQL &SQL1;
   
   &REC = CreateRecord(Record.PSRECFIELD);
   &SQL1 = CreateSQL("%SelectAll(:1) where RECNAME LIKE :2 and FIELDNAME LIKE :3");
   
   /* get global prompt */
   &status = %Super.GetUserInputByKey("Recs", &sValRecs);
   /* get class prompt */
   &status = %Super.GetUserInputByKey("Flds", &sValFlds);
   &SQL1.Execute(&REC, Upper(&sValRecs | "%"), Upper(&sValFlds | "%"));
   While &SQL1.Fetch(&REC)
      &iCount = &iCount + 1;
      &status = %Super.InsertData("String", "Record: " | &REC.RECNAME.Value | "
 has the following field that matches your criteria: ", &REC.FIELDNAME.Value);
   End-While;
   
end-method;

method IsPlugIn
end-method;

If you only need to define the class level prompt, use only the second InsertQuestion() method in the GetDynamicPrompt() method and one GetUserInputByKey().

If the message is not required during the dynamic input, then pass an empty string in the second parameter of the InsertQuestion() method.

This example demonstrates the join between two records. This join can be done by creating a view also.

In this example, the plug-in retrieves the objects from the PSLOCK and PSVERSION tables where versions of the objects don’t match.

import PT_DIAGNOSTICS:*;

class MatchVersions extends PT_DIAGNOSTICS:PTDiagnostics
   /* Constructor */
   method MatchVersions();
   
   /* Public Method */
   method GetDiagnosticInfo();
   method IsPlugIn();
   
private
   
end-class;

method MatchVersions;
   Local boolean &status = False;
   %Super = create PT_DIAGNOSTICS:PTDiagnostics();
   &status = %Super.SetProperty(%This, "Purpose", "String", "This is to retrieve
 the objects whose versions doesnot match in PSLOCK and PSVERSIONS.");
end-method;

method GetDiagnosticInfo
   Local boolean &status;
   Local Rowset &rs1;
   Local Rowset &rs2;
   Local integer &i, &j;
   Local Row &ro1;
   
   &rs1 = CreateRowset(Record.PSVERSION);
   &rs1.Fill();
   
   &rs2 = CreateRowset(Record.PSLOCK);
   &rs2.Fill();
   
   For &i = 1 To &rs1.RowCount
      For &j = 1 To &rs2.RowCount
         If (&rs1.GetRow(&i).GetRecord(Record.PSVERSION).OBJECTTYPENAME.Value =
 &rs2.GetRow(&j).GetRecord(Record.PSLOCK).OBJECTTYPENAME.Value) And
               (&rs1.GetRow(&i).GetRecord(Record.PSVERSION).VERSION.Value <>
 &rs2.GetRow(&j).GetRecord(Record.PSLOCK).VERSION.Value) Then
            &status = %Super.InsertData("String", "OBJECTTYPENAME: ", &rs1.GetRow
(&i).GetRecord(Record.PSVERSION).OBJECTTYPENAME.Value | " PSVERSION.VERSION: "
 | &rs1.GetRow(&i).GetRecord(Record.PSVERSION).VERSION.Value | " PSLOCK.VERSION: "
 | &rs2.GetRow(&j).GetRecord(Record.PSLOCK).VERSION.Value);
         End-If;
      End-For;
   End-For;
   
   
end-method;

method IsPlugIn
end-method;

The following example demonstrates error handling when the constructor fails.

import PT_DIAGNOSTICS:*;

class TestFailedConstructor extends PTDiagnostics
   /* Constructor */
   
   method TestFailedConstructor();
   
   /* Public Method */
   method GetDiagnosticInfo();
   method IsPlugIn();
   
private
   instance boolean &constructorFailed;
end-class;

method TestFailedConstructor
   Local boolean &status;
   Local string &sError;
   %Super = create PTDiagnostics();
   
   &status = %Super.SetProperty(%This, "Purpose", "String",
 "This is a diagnostic to show how developers can trap a failure
 in the constructor and print out results to the web page.");
   
   /* introduce unknown propName of Where1 rather than Where */
   &status = %Super.SetProperty(%This, "Where1", "Boolean", True);
   
   If Not &status Then
      %This.constructorFailed = True;
   Else
      %This.constructorFailed = False;
   End-If;
   
end-method;

method GetDiagnosticInfo
   Local string &sError, &sLicenseCode, &sLicenseGroup;
   Local boolean &status;
   
   If %This.constructorFailed Then
      &status = %Super.InsertData("String", "Status Failed!",
 "This message will be printed out in the HTML page if something
 fails in the constructor.  This is expected behaviour.");
   Else
      SQLExec("SELECT LICENSE_CODE, LICENSE_GROUP FROM PSOPTIONS",
 &sLicenseCode, &sLicenseGroup);
      
      &status = %Super.InsertData("String",
 "Your License Code is: ", Upper(&sLicenseCode));
      
   End-If;
end-method;

method IsPlugIn
end-method;

The following example demonstrates error handling when InsertData fails.

import PT_DIAGNOSTICS:*;

class TestFailedGetDiagnosticInfo extends PTDiagnostics
   /* Constructor */
   
   method TestFailedGetDiagnosticInfo();
   
   /* Public Method */
   method GetDiagnosticInfo();
   method IsPlugIn();
   
private
   
end-class;

method TestFailedGetDiagnosticInfo;
   Local boolean &status;
   %Super = create PTDiagnostics();
   &status = %Super.SetProperty(%This, "Purpose", "String",
 "This is a diagnostic to show how developers can trap a failure in
 GetDiagnosticInfo method and print out results to the web page.");
end-method;

method GetDiagnosticInfo
   Local string &sError, &sLicenseCode, &sLicenseGroup;
   Local boolean &status;
   
   SQLExec("SELECT LICENSE_CODE, LICENSE_GROUP FROM PSOPTIONS",
 &sLicenseCode, &sLicenseGroup);
   /* introduce unknown propFormat of String1 */
   &status = %Super.InsertData("String1",
 "Your License Code is: ", Upper(&sLicenseCode));
   
   If Not &status Then
      &status = %Super.InsertData("String", "Status Failed!",
 "This message will be printed out in the HTML page if
 something fails here.  This is expected behaviour.");
   End-If;
end-method;

method IsPlugIn
end-method;

The following example demonstrates error handling when retrieving user prompts.

import PT_DIAGNOSTICS:*;

class TestFailedGetUserInputByKey extends PTDiagnostics
   /* Constructor */
   method TestFailedGetUserInputByKey();
   
   /* Public Method */
   method GetDiagnosticInfo();
   method IsPlugIn();
   
private
   
end-class;

method TestFailedGetUserInputByKey;
   Local boolean &status = False;
   %Super = create PTDiagnostics();
   &status = %Super.SetProperty(%This, "Purpose", "String",
 "This is a diagnostic to test getting a 'False' from GetUserInputByKey.");
end-method;

method GetDiagnosticInfo
   Local boolean &status = False;
   Local string &sVal, &sError;
   Local number &iCount = 0;
   Local Record &REC;
   Local SQL &SQL1;
   
   &REC = CreateRecord(Record.PSRECDEFN);
   &SQL1 = CreateSQL("%SelectAll(:1) where RECNAME LIKE :2");
   
   /*
 sKeyID "Recs" has already be defined elsewhere in the package
 see if we can get RecJY.  should get a False
*/
   &status = %Super.GetUserInputByKey("RecsJY", &sVal);
   If &status Then
      &SQL1.Execute(&REC, Upper(&sVal | "%"));
      While &SQL1.Fetch(&REC)
         &iCount = &iCount + 1;
         &status = %Super.InsertData("String", "Record #" | &iCount,
 &REC.RECNAME.Value | " (" | &REC.RECDESCR.Value | ")");
      End-While;
   Else
      &status = %Super.InsertData("String", "Status Failed!",
 "Failed status encountered in retrieving RecsJY key.
 This is expected behaviour.");
   End-If
end-method;

method IsPlugIn
end-method;