PeopleCode

Running an SQR from within your PeopleCode program

Therefore, the best and safest way to launch an SQR program is to use the People Code functions CreateProcessRequest() and Schedule(). The CreateProcessRequest function allows you to create a Process Request object. Remember, you should be coding your People Code programs using the Object Oriented methods. Once you’ve created your object, you can assign values to its properties and use the Schedule method to submit the process request for scheduling. The CreateProcessRequest function takes 2 arguments. The Process Type and the Process Name.

REM Declare your Variables;

Code to insert any data from file to Record using Appengine

we need to create an AET record and Base Record (if it is anew record or else we can use the existing Record). Then create a RunControl Page with the fields File Path Name, Record Name.

SQL Code:
%SelectInit (FILE_PATH_NAME, RECNAME)
 SELECT FILE_PATH_NAME
 , RECNAME
  FROM %Table (XX_XXXXX_RUN1)
 WHERE OPRID=%OperatorId
   AND RUN_CNTL_ID=%RunControl

People Code:

Local File &MYFILE, &MYFILE1;
Local string &PATH_READ, &PATH_WRITE, &REC, &rec_value;
Local array of string &values;
Local Record &rec1;
&DATE = %Datetime;

Code to know whether the Scheduled App Engine ran to success or not

  If &MYRQST.Status = 0 Then /* if Schedule status is success */

      &LOOP = 0;
      While &LOOP = 0
         SQLExec("SELECT A.DISTSTATUS, A.RUNSTATUSDESCR FROM PS_PMN_PRCSLIST A WHERE A.PRCSNAME = :1 AND A.PRCSINSTANCE = (SELECT MAX(B.PRCSINSTANCE) FROM PS_PMN_PRCSLIST B WHERE B.PRCSNAME = A.PRCSNAME)", &MyAppName, &POSTED, &STATUS);
         
         If &STATUS = "Success" And
               &POSTED = 5 Then /* Posted */
            &LOOP = 1
         End-If;
         
         If &STATUS = "Success" And /* Not Posted */

Code to Schedule App Engine thru PeopleCode

Local ProcessRequest &MYRQST;
   
   &MyAppName = "CSGC_OL_RVW";
   &MYRQST = CreateProcessRequest("Application Engine", &MyAppName);
   &MYRQST.RunControlID = "TEST";
   &MYRQST.RunLocation = "PSUNX";      
   &MYRQST.Schedule();
   
   If &MYRQST.Status = 0 Then /* if Schedule status is success */
 
  End-If;

Sending Outlook Meeting Request Using PeopleCode

The code was provided by a guest by the name of Nate. I wanted to post the code as a blog entry to give it more visibility. The original forum question is http://compshack.com/forum/peoplesoft/peoplesoft-technical/sending-meeti...

I haven't used/tested the code, so please provide your feedback in the comments section below if you have.

import PT_MCF_MAIL:*;

/*Declare variables*/
Local Record &cache = CreateRecord(Record.Z_CAL_CACHE);
Local string &guid;
Local string &url;

Dynamic Prompt Table Depending on a Drop Down Value

In this post I will attempt to explain how to dynamically assign a prompt table depending on a drop down value (see image below)

The table behind the grid is PORTAL_SECDYVW and as you can see from the image below, the PORTAL_AUTHNAME field has %EDITTABLE defined as a prompt table. The PORTAL_AUTHNAME is the "Name" column you see on the grid.

Delete All Grid Rows

A very simple yet very useful code to give users the option to delete all grid rows on a page at once. I've implemented such a requirement by placing a "Delete all" button above a grid to give PeopleSoft users the option to delete all rows at once instead of clicking the "-" grid button. If the gird has, lets say, 20 rows, then a user will have to click the "-" delete grid button 20 times to delete all rows, compared to one click on the "Delete all" button.

Place the code below behind a field change event.

   &RECCNT = ActiveRowCount(Record.record_name_behind_grid);

Leading Zero Issue in CSV/Excel Formatterd Report

If you use APP ENGINE to report the data from the temp table /staging table on to CSV file using excel format, there is a known issue with fields that have leading zeros. For ex:You have a field of length 6 characters. If the field value is 002123, the excel file removes the leading zeros. But if the requirement is to preserve those leading zeros, we can do something like this.
Update the temp table right before you write out into a file.

Update %Table(Temp_Stg) A
Set A.Field = (Select '"='||A1.Field||'"' from  %Table(Temp_Stg) A1 where A1.Keyfield = A.Keyfield)

Function to Increment a Date Field

The function increments a date field using the AddToDate function and sets a weekday field to the corresponding weekday. You can increment date value by year, month or day.

Function increment_date(&DATE, &WEEKDAY, &YEAR_INCREMENT, &MONTH_INCREMENT, &DAY_INCREMENT);
   If All(&DATE) Then
      &DATE = AddToDate(&DATE, &YEAR_INC, &MONTH_INC, &DAY_INC);
      /*get day value for the incremented date*/
      &WEEKDAY = String(Weekday(&DATE));
   End-If;
End-Function;

Function to Add Leading Characters to a Value or Field

A function to facilitate the addition of a leading character to a field value. The function takes three parameters:
- &LEADCHAR: The character you want to append to your value.
- &FIELDZISE: The over all size of your value after appending your desired character.
- &FIELDVALUE: The value you want to append the character to.

Function add_leading_char(&LEADCHAR, &FIELDSIZE, &FIELDVALUE, &RESULTFIELD);