PeopleCode

Dynamic Drop Down(Translate Values)

This code i have got Ittool box.com.
It is very useful. we usually have requirement when we want to hide some translate values from translate field on page for some business reason.
In this case we can use AddDropDownItem(),ClearDropDownItem().
The fact is that we need to use ClearDropDownItem() function first. so whatever values it had will be cleared out and then we will have to manually add values using AddDropDownItem().

Here is an example on the page activate PeopleCode.

Local Field &fField;

&fField = Record.EX_APR_WRK.APPROVAL_STATUS;

Call Unix Script from PeopleCode

A function to call UNIX and/or shell script from PeopleCode.

/*call unix script from PeopleCode*/
Function CallScript;

   /*According to PeopleBooks, PS_HOME is always prefixed to the file location*/
   &exitCode = Exec("/path/to/script/scriptname ", True);

End-Function;

The Exec command has changed in PT8.4x so the above function will be:

Function CallScript;
 
   /*Use %Exec_Asynchronous if it is not important to wait for a response from the called script*/

Hide a Subpage Using PeopleCode

There was a question asked on the forum on how to hid a subpage. There is no Peoplecode function to hide a subpage directly, BUT one way around that is putting the subpage in a group box and hid the group box instead. Hiding the group box will end up hiding your sub page.

Make sure to follow the following post, it will walk you through how to hide a group box on a page.

Delete PeopleSoft Query From the Database

There could be different reasons why a PeopleSoft developer would like to delete a query from the database. Upgrade clean up would probably be the most common one. Here is a function you can use to get you started.

Function DeleteQuery(&sQueryName As string)
   SQLExec("DELETE FROM PSQRYDEFN WHERE QRYNAME=:1", &sQueryName);
   SQLExec("DELETE FROM PSQRYSELECT WHERE QRYNAME=:1", &sQueryName);
   SQLExec("DELETE FROM PSQRYRECORD WHERE QRYNAME=:1", &sQueryName);
   SQLExec("DELETE FROM PSQRYFIELD WHERE QRYNAME=:1", &sQueryName);

Generic Scroll PeopleCode

We always find it confusing to write code for Scrolls. Following is generic peoplecode which you can use for pages having parent child relationships (scrolls).

Just replace the record and field for respective level.

&rs_level0 = GetLevel0();

&level0fieldvalue = &rs_level0.(1).Level0_Record.Level0_field.Value ;

&row_level0 = &rs_level0.GetRow(1);
&rs_level1 = &row_level0.GetRowset(Scroll.Level1_Record);
For &J = 1 To &rs_level1.RowCount

   &level1fieldvalue = &rs_level1.GetRow(&J).Level1_Record.Level1_field.Value
   
   &row_level1 = &rs_level1.GetRow(&J);

Writing XLS file using SQR and PeopleCode

We can write a XLS file using PeopleCode and SQR. We will be simply writing a XLS file using HTML tags.
Below is the SQR code.

Let $filename='C:\PeopleSoft\PsftHRMS90\'||$Prcs_Process_Instance||'\Report'||$Prcs_Process_Instance||'.xls'
Open $filename  as 2 for-writing record=20000 status=#filestat2
<*start of  table *>
Write 2 from '<table border = 1>'

<*start of heading row*>
Write 2 from '<tr>'
<*heading cell tag, we can have multiple headings cells in a heading row*>
Write 2 from '<th>'
Write 2 from  $head
Write 2 from '</th>'
<*end of heading cell tag*>

Upload Files in PeopleSoft (File Attachment)

Giving PeopleSoft users the ability to upload files from a page by using the infamous "Browse" button is something that you will most likely do at one point in your PeopleSoft career. As a matter of fact, some questions are popping up on the forum asking for a sample code to get the above requirement accomplished.

Convert From One Currency to Another

Always return to Peoplebooks when you are about to write a new function. A quick search might save you a lot of time. This is what I've done when I was about to write a new function to convert currency from US dollar to any other currency on the PS_RT_RATE_TBL (rate table).

PeopleSoft already delivers such a function for you to use. The function is ConvertCurrency.

ConvertCurrency(amt, currency_cd, exchng_to_currency, exchng_rt_type, effdt, converted_amt [, error_process [, round] [, rt_index]])

Check for Data Duplicates on a Grid

Here is a piece of code to prevent duplicate data on a specific field on a page grid. You can of course modify it to check for multiple fields or even the whole row.

   /* Check for data duplicates on a grid. */
   Local Row &row1, &row2;
   Local number &r, &r1;
   
   &rs = GetLevel0().GetRow(1).GetRowset(Scroll.grid_table);
   
   For &r = 1 To &rs.ActiveRowCount
   /*Get grid row*/
      &row1 = &rs.GetRow(&r);
      /*once we have a row, we are going to loop through the grid rows and make sure a specific field value is unique*/

Compare Report in CSV or HTML format

Click here -> Compare Report in HTML format to see how you can generate compare reports in HTML or CSV format.