Archive for November, 2013


PeopleSoft Tip: Unique way to get filename from file path

Here’s a simple peoplecode snippet to get filename from given file path. The file name returned for below code is “Phani.csv”

1) For Unix File Path

&UnixFilePath = “/psoft/hr91/devbox/data/stage_in/arch/Phani.csv”;

Local Array of String  &FilePath;
   &FilePath = Split(&UnixFilePath, “/”);
   &Filename = &FilePath [&FilePath.Len];

Or

2) For Windows File Path

&WindowsFilePath =  “\\psoft\hr91\devbox\data\stage_in\arch\Phani.csv”; 

Local Array of String  &FilePath;
   &FilePath = Split(&WindowsFilePath, “\”);
   &Filename = &FilePath [&FilePath.Len];

Advertisements

PeopleCode to Archive files from Inbound folder to Archive Folder.

&Filename is File Name.

FILE_INPUT: To get input file path for the file name &Filename.

FILE_INPUT_ARCH: To get Archive file path for the files.

Global string &Filename;

&filetype = “FILE_INPUT”;
SQLExec(“SELECT A.FILE_DIRECTORY FROM PS_AE_FILE_DIR A WHERE A.NAME1 = :1”, &filetype, &file_path);
&filetypearch = “FILE_INPUT_ARCH”;
SQLExec(“SELECT A.FILE_DIRECTORY FROM PS_AE_FILE_DIR A WHERE A.NAME1 = :1”, &filetypearch, &arch_path);

MessageBox(0, “”, 0, 0, “Action : Archive”);
If FileExists(&file_path | &Filename, %FilePath_Absolute) Then
   &Str = “gzip ” | &file_path | &Filename;
   &exitcode1 = Exec(&Str, %Exec_Asynchronous + %FilePath_Absolute);
   If &exitcode1 = – 1 Then
      MessageBox(0, “”, 0, 0, &Filename | ” has been compressed “);
   Else
      MessageBox(0, “”, 0, 0, “ERROR: ” | &Filename | ” File compress failed. “);
      &strErr = “ERROR: ” | &Filename | ” File compress failed. “;
      Error &strErr;
   End-If;
   &gzip_file = &file_path | &Filename | “.gz”;
   &Str_cmd = “mv ” | &gzip_file | ” ” | &arch_path | &Filename | “-” | %Datetime | “.gz”;
   &exitcode = Exec(&Str_cmd, %Exec_Asynchronous + %FilePath_Absolute);
   If &exitcode = – 1 Then
      MessageBox(0, “”, 0, 0, &Filename | ” has been archived in ” | &arch_path);
   Else
      MessageBox(0, “”, 0, 0, “ERROR: ” | &Filename | ” File archive failed. “);
      &strErr = “ERROR: ” | &Filename | ” File archive failed. “;
      Error &strErr;
   End-If;
Else
   MessageBox(0, “”, 0, 0, “ERROR: ” | &Filename | ” File not found in: ” | &file_path);
   &strErr = “ERROR: ” | &Filename | ” File not found in: ” | &file_path;
   Error &strErr;
End-If;

If we do not use required field property and we need to highlight a required field on a page, we need to use peoplecode on saveedit event as below:

Setcursorpos(%Page):It is to position the cursor to the required field in a specific page.

Style = “PSERROR”: Property which turns the field into Red color which is the default behavior of an error message;

If (conditions) Then
 Recordname.Fieldname.Setcursorpos(%Page);
 Recordname.Fieldname.Style = “PSERROR”; 
   &error1 = MsgGetExplainText(25, 18, “Message not found”);
   &error1 = MsgGetExplainText(99999, 1, &error1); /* 99999,1 should not have any text*/
   Error (&error1);

End-If;

 

Sometimes it will be necessary to control display of field formats through peoplecode.

Example: In PeopleSoft ,a signed number needs to be displayed as integer on a page.That is remove decimals from page display using peoplecode.

We will be using FieldClass for modifying such field properties.

Example:

Write Below Code on Component Record RowInit PeopleCode event

Record.Field.DecimalPosition = 0; {Here 0 is the decimal position which is required to be displayed on page}

JOB.AMT1.DecimalPosition = 0;

PeopleSoft Tip : Dynamic Call Sections

There are multiple situations when we need to call sections in an Application engine dynamically. To elaborate, we might need to call Section 1 or section 2 based on what is the processing logic.
Below are the steps that need to perform to set it up.
1.  Add the fields AE_APPLID and AE_SECTION to your state record. this is the default state record that you create for the application engine.
2. In PeopleCode step, set the value of AE_APPLID to the application engine program name that you are calling. the setting will generally be based on an If/Else or a conditional statement result.  If it is a section in the same application engine program, you can leave this blank and it will default to the current running application engine program.
3. In a PeopleCode step, set the value of AE_SECTION to the section of the application engine program you are calling. The SE_SECTION and AE_APPLID need to be set to ensure dynamic invocation of Step.
4. Finally set the dynamic flag check box on the call section step