Tuesday 29 January 2013

How to populate grid dynamically using peoplecode

In this article we would see how to populate a Grid dynamically using PeopleCode. Here we use a Dynamic View SGK_VCHR_DVW as the main record of the Grid.
The grid is placed on level 1 of a secondary page and is populated using Peoplecode written in the Activate event of the secondary page. We use the SQL object &VCHRS_GRD_SQL to fetch some Voucher IDs and Vendor IDs from the database and populate the grid with these values.

Local SQL &VCHRS_GRD_SQL;
/* SQL object for fetching the vouchers and vendors*/
Local Rowset &VCHRS_GRD_RS;
/*Rowset for accessing the Grid*/
 
&VCHRS_GRD_SQL = CreateSQL("SELECT V.VOUCHER_ID, V.VENDOR_ID FROM PS_VOUCHER V 
WHERE V.BUSINESS_UNIT =:1 AND V.ACCOUNTING_DT > :2", &SGK_BU, &SGK_ACCTG_DT);
/*creating the SQL statement*/
 
&VCHRS_GRD_RS = GetLevel0()(1).GetRowset(Scroll.SGK_VCHR_DVW);
/*creating a rowset corresponding to the grid */
 
While &VCHRS_GRD_SQL.Fetch(&GRD_VOUCHER_ID, &GRD_VENDOR_ID)
&VCHRS_GRD_RS(1).SGK_VCHR_DVW.VOUCHER_ID.Value = &GRD_VOUCHER_ID;
/*assigning the voucher ID to the filed in the grid */
&VCHRS_GRD_RS(1).SGK_VCHR_DVW.VENDOR_ID.Value = &GRD_VENDOR_ID;
/*assigning the Vendor ID to the filed in the grid */
&VCHRS_GRD_RS.InsertRow(0);
/* inserting a new row at the beginning of the grid*/
End-While;
 
&VCHRS_GRD_RS.DeleteRow(1);
/* deleting the empty row left after all the insertions */
&VCHRS_GRD_SQL.Close();
/* closing the SQL object */

Adding Drop Down List From Peoplecode

Today we will see adding values to a drop down list through Peoplecode. This method becomes essential if you want to dynamically populate the drop down list based on some condition. The example given here shows what need to be written in the page activate of a secondary page that is called from a grid on the main page. It expects a component variable &rownum that indicates the row on which the code should fire

Component number &rownum;
/* The component variable for passing the rownum from the standard page to the secondary page */
 
Local SQL &SQL;
Local Rowset &rset0, &rset1;
Local String &type, &descr;
/* Note the SQL and the Rowset objects */
 
&rset0 = GetLevel0();
&rset1 = &rset0(1).GetRowset(Scroll.LEVEL1_REC);
/* Getting the level0 and level1 records */
 
&FLD = &rset1(&rownum).GetRecord(Record.LEVEL1_REC).GetField(Field.LEVEL1_REC_FIELD);
/* Getting the required filed to which the drop down is attached */
 
&FLD.ClearDropDownList();
/* Clearing all existing values that were with AddDropDownItem() */
 
&SQL = CreateSQL("SELECT A.TYPE, A.DESCR FROM PS_ABCD_TBL A WHERE A.EFF_STATUS = 
'A' AND SOME CONDITION");
/* Creating SQL for fetching values to be added to the drop down */
 
While &SQL.Fetch(&type, &descr)
&FLD.AddDropDownItem(&type, &descr);
/* Adding each row from the SQL's output to the drop down  */
End-While;

Sunday 11 November 2012

Sending Mail through the people code

You can use the SendMail People Code function to send emails from within People Code. You can also call this function from an Application Engine.  
Note: Make sure your SMTP server is configured properly or the SendMail function will fail.

Local string &MAIL_CC, &MAIL_TO, &MAIL_BCC, &MAIL_SUBJECT, &MAIL_TITLES, &MAIL_TEXT, &MAIL_FILES, &MAIL_FROM, &REPLYTO, &SENDER;

Local number &MAIL_FLAGS;

&MAIL_FLAGS = 0;
&MAIL_TO = "email-address-message-going-to";
&MAIL_CC = "";
&MAIL_BCC = "";
&MAIL_SUBJECT = "Test email";
&MAIL_TEXT = "Sending an email from PeopleCode.";
&MAIL_FILES = "";
&MAIL_TITLES = "";
&MAIL_FROM = "email-address-message-is-from";
&MAIL_SEP = ";";
&CONTTYPE = "";
&REPLYTO = "";
&SENDER = "";

&RET = SendMail(&MAIL_FLAGS, &MAIL_TO, &MAIL_CC, &MAIL_BCC, &MAIL_SUBJECT, &MAIL_TEXT, &MAIL_FILES, &MAIL_TITLES, &MAIL_FROM, &MAIL_SEP, &CONTTYPE, &REPLYTO, &SENDER);

If &RET <> 0 Then
 MessageBox(0, "", 0, 0, "Return code from SendMail= " | &RET);
 /*Do error processing here*/
End-If;

Monday 5 November 2012

PeopleSoft Questions and Answer

1. What is PIA and what are its components?
It is n-tier architecture. We have client, web server, application server and Database server. We have jolt and tuxedo. We have WSL, WSH, JSL, JSH, QUEUES and services.
In database server we have system tables, peopletools tables and application tables.

2. Differentiate Field edit and Save edit?In Field edit for each field change, a transition to the application server to the database is taken place. In Save edit for all the fields, only one transition to the application server to the Database is taken place.

3. What are think time functions?
Think-time functions suspend processing either until the user has taken some action (such as clicking a button in a message box), or until an external process has run to completion.

4. In which events error & warning are used most extensively.
Field edit, Save edit, Search save, row delete, row insert.

5. Is there any way by which you can find out whether the user is in Add mode or Update mode?
%mode---returns A---for Add mode. Returns U –for Update mode

6. What is the purpose of the SQLEXEC function? What are its benefits and draw backs?
SQLEXEC is used to execute the sql statements (select, insert,update,delete).
We can get only one row at a time.

7. How is the searchinit event most often used by people soft application?
A) Searchinit fires before the search dialogue page is displayed to the end user.For this reason searchinit is often used to enhance roll level security by inserting and graying out certain values to the search dialogue page.

8. What are the options for using SQL in people code?
a) Sqlexec
b) Record class methods (selectbykey, delete, insert, update)
c) Using sql class, its properties and methods.

9. What is the difference between component buffer and data buffer?
Component buffer contains all the data of the active component.
Data buffer contains the data other than the data in the component buffer (Data of other records)

10. What databuffer classes are available in people code?
Rowset, Row, Record, Field, Array, File, Sql, chart, grid and so on.

11. When we select a component what events will be fired?
If default mode for component is search mode: only searchinit will fired .If default mode for component is new mode :field default, field formula, rowinit, searchinit.

12. What are different variables in people code and their Scope?
System variables and User defined variables.
Scope --- Global, Component, Local.

13. What is default processing?
In default processing, any blank fields in the component are set to their default value. You can specify the default value either in the Record Field Properties, or in FieldDefault PeopleCode

14. What is difference between field default and Row init?
Field default specifies only the default value for a field when we are in Add mode.
Row init fires only when a row of data coming from database to component buffer.

15. What is difference between saveprechange and savepostchange? Which function directly interacts with the database?
Saveprechange---last event that executes before updating the data from component buffer to the database.
Savepostchange –fires after the updation of data in the database.
SQLEXEC --- function directly interacts with the database.

16. What is Getlevel 0()? What is the use of %subrec and %selectall functions?
Getlevel0 ()---used the get the rowset of the level0.
%subrec--is used only in Dynamic View SQL where it expands to the columns of a subrecord:
%selectall--%SelectAll is shorthand for selecting all fields in the specified record, wrapping date/time fields with %DateOut, %TimeOut.

17. What is an array in people code? What is maximum dimension of an array? Which function inserts values into an array? What is “pop”?
An array is a collection of data storage locations, each of which holds the same type of data.
The maximum depth of a PeopleCode array is 15 dimensions.
Push and unshift are the functions of the array used to add the elements into the array one from the end of the array and one from the beginning.
Pop is a function of array used to select and delete an element from the end of the array.

18. What is difference between Getrowset and Createrowset in people code?
Getrowset –is used to get rowset for a record in the component buffer.
Createrowset—is used to create rowset for a record which in database, and is also called a Standalone rowset

19. Can you save the component programmatically?
Using Dosave and Dosavenow functions.

20. What is differed processing and its advantages?
Postpones some user actions to reduce the number of trips to the database so that increases the performance (in system edits, field edit, and field change).
Advantages:
1) Reduces the network traffic.
2) Increases the performance.
33. Write the syntax to access third level record field using object oriented peoplecode?
&fld=Getlevel0 ()(1).GetRowset(Record..GetRow(1),
GetRowset (Record.).GetRow(1),
GetRowset (Record.).GetRow(1),
GetRecord (Record.).GetFieild(Field.))

21. What are the built-functions used to control translate values dynamically?
Adddropdownitem ()
Deletedropdownitem ()

22. How to populate data into grid in online?
&Rs.Select or Scrollselect ().
SECURITY
Before accessing a people soft application what levels of security must be passed through.
a) Field level security
b) Row level security
c) Maintain security
d) Definition security
e) Portal security.

23.What is the use of primary permission list in user profile?
Primary permission list is used for mass change and definition security purposes.
How to authorize the user to run a process or report?
To authorize a user to run a process, the process group, which contains the process or report, should be added to the permission list of that user.

24.How to give access to the records that are to be used in a query?
To give access to the records that are to be used in query, we have create a new query security tree and add the records which we want to give the access and then assign a access group to the tree. After that we have to add that query tree and query access group to the permission list.

25.What are the rules used by the system to determine whether a user is authorized to update an object?
The user should have the permission to update the object. This is given by the Definition security. The group, which holds the object, should be added to the permission list of the user in update mode.
What are the different ways we can set up the portal security to access component in portal?
1) Structure & content
2) Menu import
3) Register component