Example of Accessing the Repository Using PeopleCode

This example gets information for the class ABS_HIST from the Namespace component interface and writes it to the file BC.TXT:

This is the complete code sample, followed by the flat file. The next section presents steps that explain each line.

Local ApiObject &MYSESSION;
Local ApiObject &MYCI;
Local string &OutTEXT;
Local File &MYFILE;
&MYSESSION = %Session;

&MYFILE = GetFile("CI.txt", "A", "UTF8");
&NAMESPACES = &MYSESSION.Repository.Namespaces;
&NAMESPACE = &NAMESPACES.ItemByName("CompIntfc");
&OutTEXT = "Namespace = " | &NAMESPACE.Name;
&MYFILE.WriteLine(&OutTEXT);
&CLASSES = &NAMESPACE.classes;
&CLASS = &CLASSES.ItemByName("ABS_HIST");
&OutTEXT = "  Class: " | &CLASS.Name;
&MYFILE.WriteLine(&OutTEXT);
&OutTEXT = "     Methods";
&MYFILE.WriteLine(&OutTEXT);
&METHODS = &CLASS.methods;
For &K = 0 To &METHODS.Count - 1
   &METHOD = &METHODS.item(&K);
   &OutTEXT = "             " | &METHOD.name | ":  " | &METHOD.Type

   &MYFILE.WriteLine(&OutTEXT);
   &ARGUMENTS = &METHOD.arguments;
   For &M = 0 To &ARGUMENTS.count - 1
      &ARGUMENT = &ARGUMENTS.item(&M);
      &OutTEXT = "           " | &ARGUMENT.name | ": " | &ARGUMENT.type;
      &MYFILE.WriteLine(&OutTEXT);
   End-For;
End-For;
&OutTEXT = "     Properties";
&MYFILE.WriteLine(&OutTEXT);
&PROPERTIES = &CLASS.properties;
For &I = 0 To &PROPERTIES.count - 1
   &PROPERTY = &PROPERTIES.item(&I);
   &OutTEXT = "              " | &PROPERTY.name | ": " | &PROPERTY.type;
   &MYFILE.WriteLine(&OutTEXT);
End-For;
&MYFILE.Close();

The previous code produces the following flat file:

Namespace = CompIntfc
  Class: ABS_HIST
     Methods
             Get:  Boolean
             Save:  Boolean
             Cancel:  Boolean
             Find:  ABS_HIST
             GetPropertyByName:  Variant
           Name: String
             SetPropertyByName:  Number
           Name: String
           Value: Variant
             GetPropertyInfoByName:  CompIntfcPropertyInfo
           Name: String
     Properties
              EMPLID: String
              LAST_NAME_SRCH: String
              NAME: String
              ABSENCE_HIST: ABS_HIST_ABSENCE_HISTCollection
              interactiveMode: Boolean
              getHistoryItems: Boolean
              componentName: String
              compIntfcName: String
              stopOnFirstError: Boolean
              propertyInfoCollection: CompIntfcPropertyInfoCollection
              createKeyInfoCollection: CompIntfcPropertyInfoCollection
              getKeyInfoCollection: CompIntfcPropertyInfoCollection
              findKeyInfoCollection: CompIntfcPropertyInfoCollection

The PeopleCode Example Explanation

This procedure goes through the PeopleCode example line by line.

To retrieve information from the API Repository:

  1. Get a session object.

    Before you can access the PeopleSoft API Repository, you have to get a session object. The session controls access to PeopleSoft, provides error tracing, enables you to set the runtime environment, and so on.

    &MYSESSION = %Session;
  2. Open the file.

    As this text will be written to a flat file, the next step is to open the file. If the file is already created, the new text is appended to the end of it. If the file hasn’t been created, the GetFile built-in function creates the file.

    &MYFILE = GetFile("CI.txt", "A", "UTF8");
  3. Get the namespace you want.

    Use the Namespaces property on the repository object to get a collection of available namespaces. We want to discover information about a component interface, so we specify CompIntfc in the ItemByName method to get that namespace. With ItemByName, you must specify a namespace that already exists. You’ll receive a runtime error if you specify one that doesn’t exist.

    &NAMESPACES = &MYSESSION.Repository.Namespaces;
    &NAMESPACE = &NAMESPACES.ItemByName("CompIntfc");
  4. Write the text to the file.

    Because all of the information discovered is being written to a file, the next step is to write text to the file. This code writes the string “Namespace”, followed by the name of the namespace, to the file.

    &OutTEXT = "Namespace = " | &NAMESPACE.Name;
    &MYFILE.WriteLine(&OutTEXT);
  5. Get the class that you want and write text to the file.

    Use the Classes property on the Namespace object to get a collection of all the available classes. We want to discover information about the component interface named ABS_HIST, so we specify that using ItemByName. Then we write that information to the file.

    &CLASSES = &NAMESPACE.classes;
    &CLASS = &CLASSES.ItemByName("ABS_HIST");
    &OutTEXT = "  Class: " | &CLASS.Name;
    &MYFILE.WriteLine(&OutTEXT);
  6. Get the methods and arguments, and write the information to the file.

    Use the Methods property on the Class object to get a collection of all the available methods. After you get each method and write the information to the file, loop through and find all of the arguments for the method, then write that information to the file.

    &OutTEXT = "     Methods";
    &MYFILE.WriteLine(&OutTEXT);
    &METHODS = &CLASS.methods;
    For &K = 0 To &METHODS.Count - 1
       &METHOD = &METHODS.item(&K);
       &OutTEXT = "             " | &METHOD.name | ":  " | &METHOD.Type;
       &MYFILE.WriteLine(&OutTEXT);
       &ARGUMENTS = &METHOD.arguments;
       For &M = 0 To &ARGUMENTS.count - 1
          &ARGUMENT = &ARGUMENTS.item(&M);
          &OutTEXT = "           " | &ARGUMENT.name | ": " | &ARGUMENT.type;
          &MYFILE.WriteLine(&OutTEXT);
       End-For;
    End-For;
  7. Get the properties and write the information to the file.

    Use the Properties property on the Class object to get a collection of all the available properties. Write each property, with its type, to the file. At the end of the program, close the file.

    &OutTEXT = "     Properties";
    &MYFILE.WriteLine(&OutTEXT);
    &PROPERTIES = &CLASS.properties;
    For &I = 0 To &PROPERTIES.count - 1
       &PROPERTY = &PROPERTIES.item(&I);
       &OutTEXT = "              " | &PROPERTY.name | ": " | &PROPERTY.type;
       &MYFILE.WriteLine(&OutTEXT);
    End-For;
    &MYFILE.Close();