How to Send Email Using PeopleCode

How to Send Email Using PeopleCode
In this Article we can find how to send email using peoplecode
Function SendMAilfromSetupMailInfo (&ReceiverName As string, &MAIL_TO As string) Returns boolean
Local PT_MCF_MAIL: MCFOutboundEmail &ObjectEmail = create PT_MCF_MAIL: MCFOutboundEmail();

/*-- Initialize the usual fields of an email --*/

&ObjectEmail.From = "email@abc.com";
&ObjectEmail.ReplyTo = "email@abc.com ";
&ObjectEmail.Recipients = &MAIL_TO;
&ObjectEmail.Subject = MsgGetText (20050, 142, "");
&ObjectEmail.Text = MsgGetExplainText (20050, 141, "", &PersonName, &MAIL_TO);
&ObjectEmail.AddHeader("Errors-To", "email@abc.com");


Local integer &resp = &ObjectEmail.Send();
Local boolean &done;

Evaluate &resp
When %ObEmail_Delivered
/* every thing ok */
&done = True;
Break;

When %ObEmail_NotDelivered
/*-- Check &email.InvalidAddresses, &email.ValidSentAddresses
and &email.ValidUnsentAddresses */
&done = False;
Break;

When %ObEmail_PartiallyDelivered
/* Check &email.InvalidAddresses, &email.ValidSentAddresses
and &email.ValidUnsentAddresses; */
&done = True;
Break;

When %ObEmail_FailedBeforeSending
/* Get the Message Set Number, message number;
Or just get the formatted messages from &email.ErrorDescription,
&email.ErrorDetails;*/

&done = False;
Break;
End-Evaluate;

Return &done;
End-Function;



How to Scheduling and Running SQR from Peoplecode

How to Scheduling and Running SQR from Peoplecode
Description
Peoplecode provides functions like CreateProcessRequest that allows us to create a ProcessRequest object.  Once this object is created, we can assign values to its properties and then use the Schedule method to submit the process request for scheduling.The CreateProccessRequest function takes 2 arguments. The Process Type and the Process Name.
/*Variable declaration*/
Local ProcessRequest &MYPrcsRqst; 
Local String &MySQR;

&MySQR = "InsTmpTbl"

/* Creating Process Request Object*/
&MYPrcsRqst = CreateProcessRequest("SQR Process", &MySQR);

/*Specifying the runcontrol id*/
&MYPrcsRqst.RunControlID = "BATCH"

/*Specifying the output option*/
&MYPrcsRqst.SetOutputOption("Web", "PDF", "", &MySQR); 

/* Use the Schedule() method to Schedule the SQR.*/

&MYPrcsRqst.Schedule();
If &MYPrcsRqst.Status = 0 then
/* Schedule succeeded. */
Else
/* Process (job) not scheduled, do error processing */
End-If;

How to Populate Drop down list at Runtime using PeopleCode

How to Populate Drop down list at Runtime using PeopleCode
The solution is simple, using peopleCode. In that page where you need to show all the 5 translate values, you assign that field and you don̢۪t need to worry for that page. Now, for the other page, where you need to show only 3 values, you need write peoplecode in record rowinit event. First, Store the following code given below in a function library. Then, create a SQL object which will return the required 3 field values and their descriptions from PSXLATITEM. Then pass the SQL object name, Record object name and field object name as string to the below provided source code from the rowinit event. The rowinit peoplecode will look like this:
&Rcd = "Chinnu_raavi"; /* Record name */ 
&Fld = "Chinnu_raavi"; /*field name */ 
&SQL = "Chinnu_raavi_SQL"; /* SQL object name */ 
PopulateDropDown(&Rcd, &Fld, &SQL); 

Function PopulateDropDown(&RcdName As string, &Fldname As string, &SQL_name As string)
    
   Local Field &Fld;
   Local SQL &SQL;
   Local string &CodeIn, &DescIn;
   
   &Fld = GetRecord(@("Record." | &RcdName)).GetField(@("Field." | &Fldname));
   
   &Fld.ClearDropDownList();
   &SQL = GetSQL("SQL." | &SQL_name);
   
   While &SQL.Fetch(&CodeIn, &DescIn)
      &Fld.AddDropDownItem(&CodeIn, &DescIn);
   End-While;
   
 End-Function;

Identifying modified peoplecode and PeopleSoft objects based upon OPRID and Date modified

Identifying modified peoplecode and PeopleSoft objects based upon OPRID and Date modified
SELECT DISTINCT OBJECTVALUE1, OBJECTVALUE2, OBJECTVALUE3  FROM PSPCMPROG
WHERE LASTUPDDTTM = SYSDATE 
AND (OBJECTVALUE1, OBJECTVALUE2, OBJECTVALUE3)  -- Specify PeopleSoft objects name
NOT IN 
(SELECT OBJECTVALUE1, OBJECTVALUE2, OBJECTVALUE3
FROM PSPROJECTITEM WHERE PROJECTNAME LIKE '%SS')  AND LASTUPDOPRID !='OPRID';


SELECT * FROM PSRECDEFN WHERE LASTUPDDTTM >'01-JAN-2008' AND LASTUPDOPRID NOT LIKE 'PPLSOFT';

Write in the record from the external file using File layout

Write in the record from the external file using File layout
We can get the solution for able problem using the file layout in the peoplesoft . To read in the CSV file we use the following PeopleCode using the following steps:

(1) It reads the file into a temporary record.

(2) Each line of the file is read into a string.

(3) The string is split into an array, with the value of each field in the array becoming an element in the array.

(4)The value of each field in the record is assigned a value from the array.

After additional processing (for example, converting strings into dates or numbers, verifying data, and so on) the record can be inserted into the database.
To insert the final data into the database, this code must be associated with a PeopleCode event that allows database updates, that is, SavePreChange, WorkFlow, SavePostChange, and so on. This code could also be used as part of an Application Engine program.

Local File &MYFILE;
Local Record &REC;
Local array of string &ARRAY;

&MYFILE = GetFile("c:\temp\chinnuraavi.txt", "R", %FilePath_Absolute);
&REC = CreateRecord(RECORD.ABS_HIST_TEST);
&ARRAY = CreateArrayRept("", 0);

If &MYFILE.IsOpen Then
   If &MYFILE.SetFileLayout(FILELAYOUT.ABS_HIST) Then
      While &MYFILE.ReadLine(&STRING);
         &ARRAY = Split(&STRING, ",");
         For &I = 1 To &REC.FieldCount
            &REC.GetField(&I).Value = &ARRAY[&I];
         End-For;
      /* do additional processing here for converting values */
         &REC.Insert();
      End-While;
   Else
      /* do error processing - filelayout not correct */
   End-If;
Else
   /* do error processing - file not open */
End-If;

&MYFILE.Close();

How to Call SQR program using peoplecode

How to Call SQR program using peoplecode

&Rec = CreateRecord(Record.process_table);
      &Rec.OPRID.Value = %UserId;
      &Rec.RUN_CNTL_ID.Value = &ProcessName;
      
      If (&Rec.SelectByKey()) Then
         &Rec.field1.Value = table1.field1;
         &Rec.field2.Value = table1.field2;
         &Rec.field3.Value = table1.field3;
         &Rec.field4.Value =table1.field4;
         &Rec.Update();
      Else
         &Rec.SetDefault();
         &Rec.OPRID.Value = %UserId;
         &Rec.RUN_CNTL_ID.Value = &ProcessName;
         &Rec.field1.Value = table1.field1;
         &Rec.field2.Value = table1.field2;
         &Rec.field3.Value = table1.field3;
         &Rec.field4.Value =table1.field4;
      End-If;
/*specify your desired output format and destination*/
&ProcessType = "SQR Report";
      &OutDestFormat = "PDF";
      &OutDestType = "Web";
&MYRQST = CreateProcessRequest();
      &MYRQST.RunControlID = &ProcessName;
      &MYRQST.ProcessName = &ProcessName;
      &MYRQST.ProcessType = &ProcessType;
      &MYRQST.OutDestFormat = &OutDestFormat;
      &MYRQST.OutDestType = &OutDestType;
      &MYRQST.RunDateTime = %Datetime;
      &RETURN = &MYRQST.Schedule();



People code Tutorial

People code Tutorial
People code is a language like other languages with  it’s own DataTypes , Statements.

Every People Code program is associated with an Application Designer component and with an event.

Peoplecode Locations: Record Fields ,  Menus ,  Components  Pages ,  Business Components , Application Messages ,  Application Engine.

Data Types    

NUMBER,STRING,DATE,TIME,DATETIME,ANY

Scope :

                Local Variables
                Global Variables
                Component Variables

Other Variables :

                System Variables

                Derived/Work Fields



Syntax for declaration:

   <scope> <type> &<variable_name>



Local Variables :


Temporary memory location that holds the value.

Global Variables :

 Exist for the complete session and are used to transfer values between panel groups.
Session means signin to signout is called session

Component Variables :

Exist for the duration of the current PS component.
Used to transfer values between programs on the same component


System Variables :

Internally maintained  and can be referred by the people code any time.
Begins with %.
     Ex : %Date ,%Time ,%Page ,%Menu,%Component,%DBName,%Mode etc...

Derived/Work Fields :

Used when we need to pass values from one program  to another  without the  field values being stored in the    database.
Existence limited to the current component.
They are usually display only fields on a page  or have them as invisible fields on the page



User Defined Variables:


Variables which are defined by developers starts with &.

Operators:

Mathematical  :  + ,- ,* ,/ ,** , |

Comparison : = ,!= ,<> ,>= ,<= ,< ,>

Logical       :  NOT ,AND ,OR



Functions:

User defined functions
Built-in Functions


User defined function:

Internal Peoplecode

Functions that are called directly from the same program where the function was defined without the declare function statement.

External PeopleCode

Stored as Function Libraries( derived/work records named
with prefix “FUNCLIB_”
convention is define these functions in the FieldFormula Event.


Syntax for defining or writing a function
Function <function_name> (<param1,<param2>....)
           stmt1;
           stmt2;
           return <expression>;
End-Function;


Syntax for Declaring a Function
Declare Function <function_name> PeopleCode   <Record_name.FieldName>.FieldFormula.


Built-in Functions:

Component Buffer
Used to modify,update,hide fields in the buffer area.

ActiveRowCount,AddKeyListItem,CompareLikeFields,ClearKeyList,
ComponentChanged,CopyFields,CopyRow,CurrentLevelNumber.


Conversion
Char,Code,Codeb,ConvertChar,String,Value


Current Date and Time
%CurrentDateIn,%CurrentDateOut,%CurrentDateTimeIn,
%CurrentDateTimeOut,%CurrentTimeIn,%CurrentTimeOut



Database and platform
%DbName,%DbType

Data Buffer Access
CreateRecord,CreateRowset,FlushBulkInserts ,GetField,GetLevel0 ,
GetRecord ,GetRow,GetRowset

Date and Time


Used to calculate and manipulate dates

AddToDate,AddToDateTime,AddToTime, Date,DateValue
Day,Days,Days360,Days365


String  Functions

Used to manipulate character Strings.

Number Functions

Used to manipulate numeric values

Security Functions

Used for security purpose.



Data Buffer access Classes


Field ,Record ,Row ,Rowset

Field Class

       Attributes             : Name,Enabled,Type
       Methods              :  GetLongLabel,SearchClear,SetCursorPos
       Built-In Functions: GetField.


Record Class
       Attributes            : Name ,IsChanged ,FieldCount                                          
       Methods             :  CompareFields,CopyChangedFieldsTo,CopyFieldsTo
       Built-In Functions: GetRecord
Row Class
       Attributes               : Visible ,IsChanged
       Methods                : CopyTo ,GetNexteffRow.
       Built-in Functions  : GetRow
RowSet Class
       Attributes               : ActiveRowCount
       Methods                : CopyTo ,DeleteRow ,Fill
       Built-in Functions  : CreateRowSet,GetLevel0,GetRowSet



Statements in PeopleCode


Branching Statements
if Statement:  

   syntax:  if <condition>
                        stmt1;                                                        
                             else 
                       stmt2;
                            end-if;  


Evaluate Statement


Evaluate <field or variable>
when = <value1>
                stmt1; break;
when = <value2>
                stmt2; break;
when-other
                stmt3;break;
End-Evaluate;

For Loop


  For <&variable> = <start-value> to <end-value>                            
                        [Step stepvalue>]
                                   stmt1;  stmt2;
                            End-for;