Friday 31 October 2014

Random Password Generation


 In PeopleCode, we can use the Rand function to generate a random number/password  greater than or equal to 0 and less than 1. For example:
&password="ABC" | Int(Rand( )*1000);

In case we want to generate random password using SQL ( say in Set-based processing) we can use DBMS_RANDOM package in Oracle.
SELECT DBMS_RANDOM.STRING('P', 10) FROM PS_INSTALLATION;

Monday 27 October 2014

Read Excel File Using Java in peoplecode


I have placed the jxl.jar file here "C:\PT8.53\appserv\classes" ,  here is the code



Local JavaObject &workbook = GetJavaClass("jxl.Workbook");
Local Sting &sFilePath = "C:\Users\Administrator\Desktop\munib\Book1.xls";


Local string &FILE_NAME = &sFilePath;
Local JavaObject &file = CreateJavaObject("java.io.File", &FILE_NAME);
Local JavaObject &WB = &workbook.getWorkbook(&file);
Local JavaObject &sheet = &WB.getSheet(0);

For &i = 0 To &sheet.getRows() - 1
   try
      MessageBox(0, "", 0, 0, "" | &sheet.getCell(0, &i).getContents());
   
   
   
   catch Exception &e
      MessageBox(0, "Excep-----", 0, 0, &e.ToString());
   end-try;
 
End-For;

Read Excel File Using Peoplecode


Local object &oWorkApp, &oWorkBook;
Local string &sFilePath ;
&sFilePath = "C:\Users\Administrator\Desktop\munib\Book1.xls";


&oWorkApp = CreateObject("COM", "Excel.Application");
&oWorkApp.DisplayAlerts = "False";
&oWorkBook = ObjectGetProperty(&oWorkApp, "Workbooks");


&oWorkBook.Open(&sFilePath);
&oWorkSheet = &oWorkApp.Worksheets("Sheet1");
&rowcount = &oWorkSheet.Usedrange.rows.count;
&cellcount = &oWorkSheet.Usedrange.cells.count;
&columncount = &oWorkSheet.Usedrange.columns.count;

For &i = 1 To &rowcount
         For &j = 1 To &columncount;
      &data = &oWorkSheet.Cells(&i, &j).Value;
      MessageBox(0, "", 0, 0, "data in" | &i | " row " | &j | " column :" | &data);
   
   End-For;
End-For;

&oWorkApp.ActiveWorkBook.Close();
&oWorkApp.DisplayAlerts = "True";
&oWorkApp.Quit();

Thursday 2 October 2014

Inserting Rows Using PeopleCode

Record Insert method

 If you do a single insert, use the Record Insert method.

The following is an example of using the Record Insert method:
&REC = CreateRecord(Record.GREG); 
&REC.DESCR.Value = "Y" | &I; 
&REC.EMPLID.Value = &I; 
&REC.Insert();

SQL object


 If you are in a loop and,therefore, calling the insert more than once, use the SQL object. The SQL object uses dedicated cursors and, if the database you are working with supports it, bulk insert.
A dedicated cursor means that the SQL gets compiled only once on the database, so PeopleTools looks for the meta-SQL only once. This can increase performance.
For bulk insert, inserted rows are buffered and sent to the database server only when the buffer is full or a commit occurs. This reduces the number of round-trips to the database. Again, this can increase performance.

The following is an example using a SQL object to insert rows:
&SQL = CreateSQL("%INSERT(:1)"); 
&REC = CreateRecord(Record.GREG); 
&SQL.BulkMode = True; 
For &I = 1 to 10 
   &REC.DESCR.Value = "Y" | &I; 
   &REC.EMPLID.Value = &I; 
   &SQL.Execute(&REC); 
End-For;
 
 
 
 

 
 
 

PeopleCode-Update Statement

Local  Record &REC ;
Local String &UPDSTRING;


Function getUpdateString(&REC As Record) Returns string;

For &COUNT = 1 To &REC.FieldCount;

&UPDSTRING = "Update %TABLE(:1) set ";

&UPDSTRING = &UPDSTRING | &REC.GetField(&COUNT).Name | " = ";
&UPDSTRING = &UPDSTRING | &REC.GetField(&COUNT).Value | " ";


End-For;

 &UPDSTRING = &UPDSTRING | " where %KeyEqual(:1)";
 Return &UPDSTRING;
End-Function;

-------------------------------------------------------------

Local Record &REC;
Local Sql   &SQL , SQL_UP ;


&REC = CreateRecord(Record.PSOPRDEFN);

&SQL = CreateSQL("%SELECTALL(:1) WHERE OPRID =:2", &REC, &USERID);
&SQL_UP = CreateSQL("%Update(:1)");
While &SQL.Fetch(&REC)

&SQL_UP.EXECUTE(&REC);
End-While;
&SQL_UP.CLOSE();

Wednesday 1 October 2014

Setting Variables to Null in PeopleCode

 String

Always use space to assign a null value to a string.

 Local String &Test_Str = " ";

 Number

 Use 0 (zero) to assign a null value to a number.

 
Local Number &Test_Num = 0;

 Date


If you try to assign a date variable a null value you will get an error saying that the left and right sides of the assignment are not compatible.

For instance, the following PeopleCode would error out: 



Local Date &Test_DT =NULL;

To perform this kind of assignment, you may use the Date function in the following way:


Local Date &Test_DT;
&Test_DT = DATE(0);

The Date function takes a number in the form YYYYMMDD and returns a corresponding Date value. If the date is invalid, Date displays an error message.

&Test_DT = Date(19970713);

 

Peoplecode-Changing color of Field Text

Here is the situation .

I am making a check that Interview Date should not be empty.

Peoplecode on Field Change Event of the Interview Date Field


TIME_REC.INTRVW_DT_FLD.Style = "PSEDITBOX";



Peoplecode on Field Change Event of the page save button
If (TIME_REC.INTRVW_DT_FLD.Value = "") Then
  
   SetCursorPos(Page.PageName , TIME_REC.INTRVW_DT_FLD , CurrentRowNumber());
   TIME_REC.INTRVW_DT_FLD.Style = "PSERROR";
   &MsgTXt = MsgGetText(20000, 76, "Interview Date Should not be empty.");
   Error (&MsgTXt);
End-If;