Thursday, May 30, 2013

Peoplecode Basics _ Quick reference

Basic Peoplecode References:

1. MessageBox:

Very helpful in displaying values on browser so that you will know what values are being refered to in code. Also a very helpful debugging tool.

messagebox(0, "", 0, 0, " " | );

Eg:

To display a simple text:- MessageBox(0, "", 0, 0, " Hello World");
To display a value with text :- MessageBox(0, "", 0, 0, " SETID:" | &setid);


2. Declare Function:

Declare Function FunctionName PeopleCode FUNCLIB_RECORD.FIELD FieldFormula;

Just stated off more to come soon.  :-)

3. MsgGet, MsgGetText, MsgGetExplainText Functions:

MsgGet:

Purpose: Retrieves a message from Message Catalog and substitutes values of the parameters into the text message.

MsgGet(message set, message numb, custom/default text, param1, param2,.etc);

Example: MsgGet(30001, 1, "Message not found"); - without paremeters
             MsgGet(30001, 1, "Message not found", &i,&j);  - with bind parameters.
             &i, &j parameters are used to pass values into the message text in message catelog.

Note: Message Set Number from 0 to 19999 are reserved for Peoplesoft application messages usage. 

MsgGetText: Is very similar to MsgGet except message set & message number will not appear after the text of the message.

MsgGetText(message set, message numb, "custom/default text", param1, param2,.etc);


Example: MsgGetText(30001, 1, "Message not found");

4. Translate Values:

select *
from PSXLATITEM XLAT
where XLAT.EFFDT = (
            select max(XLAT_ED.EFFDT)
            from PSXLATITEM XLAT_ED
            where XLAT_ED.FIELDNAME = XLAT.FIELDNAME
            and XLAT_ED.FIELDVALUE = XLAT.FIELDVALUE
        ) 
and xlat.eff_status = 'A'
and XLAT.FIELDNAME = 'RUNSTATUS'

5. %Mode

%Action_Add - A
%Action_UpdateDisplay - U
%Action_UpdateDisplayAll - L
%Action_Correction - C
%Action_DataEntry - E
%Action_Prompt - P

6. Working with dates : (some examples)
  •    Local integer &CurrWeekday = Weekday(&CurrDate);
  •    Local integer &CurrDay = Day(&CurrDate);
  •    Local integer &CurrMonth = Month(&CurrDate);
  •    Local integer &SourceWeekday = Weekday(&SourceDate);
  •    Local date &SourceSunday = AddToDate(&SourceDate, 0, 0, - 1 * (&SourceWeekday - 1));
  •    Local integer &SourceMonth = Month(&SourceDate);
7. Dynamic SQL Prompts:


8. Standalone rowset with fill and copy:

Local Rowset &rsSAlone;
&rsSAlone = CreateRowset(Record.SAMPLE_RECORD);
&TRG_ID = '12345';
&rsSAlone.Fill("where TRAINING_ID = :1", &TRG_ID);

&rsSAlone2 = CreateRowset(Record.SAMPLE_RECORD);
 &rsSAlone2.Flush(); -- in case u want to do it
&rsSAlone.CopyTo(&rsSAlone2);

9: SCROLL:

local rowset &RS;
&RS = GetLevel0()(1).GetRowset(Scroll.MAIN_RECORD);
for &i = 1 to &RS.ActiveRowCount
   &Rec = &RS.GetRow(&i).RECORD1;
   &fLD = &Rec.FIELD1;
   &ID  = &RS.GetRow(&i).GetRecord(Record.RECORD1).getfield(field.FIELD1).value;
end-for;

-- 2 Levels -- ;

/* Get Level 0 Rowset */
&rs0 = GetLevel0();
/* Get Level 1 Rowset */
&rs1 = &rs0(1).GetRowset(Scroll.ZZ_LEVEL1);
For &i = 1 To &rs1.ActiveRowCount
&degree = &rs1.GetRow(&i).GetRecord(Record.L1_REC).GetField(Field.L1_FLD)Value; 
   /* Get Level 2 Rowset */
   &rs2 = &rs1(1).GetRowset(Scroll.ZZ_LEVEL2); 
   For &j = 1 To &rs2.ActiveRowCount
&subject = &rs2.GetRow(&j).GetRecord(Record.L2_REC).GetField(Field.L2_FLD).value;
End-For;
End-For;

--3 levels --;

/* Get Level 0 Rowset */
&rs0 = GetLevel0();
/* Get Level 1 Rowset */
&rs1 = &rs0(1).GetRowset(Scroll.ZZ_LEVEL1);
For &i = 1 To &rs1.ActiveRowCount
&degree = &rs1.GetRow(&i).GetRecord(Record.L1_REC).GetField(Field.L1_FLD)Value; 
   /* Get Level 2 Rowset */
   &rs2 = &rs1(1).GetRowset(Scroll.ZZ_LEVEL2); 
   For &j = 1 To &rs2.ActiveRowCount
&subject = &rs2.GetRow(&j).GetRecord(Record.L2_REC).GetField(Field.L2_FLD).value;
      /* Get Level 3 Rowset */
  &rs3 = &rs2(1).GetRowset(Scroll.ZZ_LEVEL3);
For &k = 1 To &rs3.ActiveRowCount
&marks = &rs3.GetRow(&k).GetRecord(Record.L3_REC).GetField(Field.L3_FLD).Value;
End-For;
End-For;
End-For;

-- get row, get rec.. get field --

&row = GetRow().RowNumber;
&rs_man = GetLevel0()(1).GetRowset(Scroll.MAIN_REC);
&rs_man.getrow(&row).getrecord(Record.REC1).getfield(Field.FIELD1).value = "A";
&rs_man.getrow(&row).getrecord(Record.REC1).getfield(Field.FIELD2).value = "A";
&rs_man.getrow(&row).getrecord(Record.REC1).getfield(Field.FIELD3).value = "N";

10. GRID

Local Grid &MYGRID;
Local GridColumn &MYGRIDCOL;
&MYGRID = GetGrid(Page.PAGE1, "EMPL_GRID"); --- The default value is scroll 1.
&MYGRIDCOLUMN = &MYGRID.GetColumn("CHECKLIST_ITEMCODE");

&MYGRID.GetColumn("SAA_DESCR1").Label = ;

11. rowset delete row 

For &I = &RS2.ActiveRowCount To 1 Step -1
   If None(&SEQ) Then
      &RS2.DeleteRow(&I);
   End-If;
End-For;

12. Dynamically change Xlat values

Local Rowset &Xlat;
 &Xlat = CreateRowset(Record.PSXLATITEM);
 &Xlat.Flush();
 &Xlat.Fill("Where fieldname = 'Field Name' order by decode(Fieldvalue,'Jan',1,0),fieldvalue");
 RECORDNAME.FIELDNAME.ClearDropDownList();
 &j = &Xlat.ActiveRowCount + 1;
 For &i = 1 To &Xlat.ActiveRowCount
    &Value = &Xlat.GetRow(&i).PSXLATITEM.FIELDVALUE.Value;
    &Descr = &Xlat.GetRow(&i).PSXLATITEM.XLATLONGNAME.Value;
    RECORDNAME.FIELDNAME.AddDropDownItem(&Value, Rept(Char(9), &j - &i)
&Descr);
End-For;

13. Using the IsUserInRole Function to check user security: 
 
   If IsUserInRole(&ValidRole_Rec.ROLENAME.Value) Then
   &user_has_access = True;
End-If;

More to be added soon.