Sunday, February 8, 2009

Add JavaScript & AJAX to PeopleSoft Page

Ajax (asynchronous JavaScript and XML), or AJAX, is a group of interrelated web development techniques used for creating interactive web applications or rich Internet applications. With Ajax, web applications can retrieve data from the server asynchronously in the background without interfering with the display and behavior of the existing page.

There are plenty of uses for this technology inside of PeopleTools. For example, in PeopleSoft a full page refresh for a FieldChange event is very expensive. While there is not currently a way to update the component buffer using AJAX, you can use it to grab and display information that would normally require the user to navigate to another page. You can do this without modifying and delivered code.

AJAX frameworks provide the infrastructure required to post data to the server without requiring a full page refresh. Furthermore, AJAX frameworks can update a portion of a page with the results of a server operation. I just finished working on Auto-Save functionality where the push of a button is automatically done every 10 minutes if there is unsaved data on a page.

I use the jQuery library when working with javascript and ajax. jQuery is a new type of JavaScript library. jQuery is a fast, concise, JavaScript Library that simplifies how you traverse HTML documents, handle events, perform animations, and add Ajax interactions to your web pages. jQuery is designed to change the way that you write JavaScript.

Here are the steps to working with Javascript and AJAX on a page.

Step One:

Since we will be working with a JavaScript library, we need to ensure that we add a call to the JavaScript library somewhere on the page we are working with. This can be done by placing the .js file onto the web server and including it on the page. However, most developers do not have access to the web server and there is an easier way to do this. You can place the JavaScript library code into a message definition. Either way, the first step is to insert an HTML Area object onto the page within Application Designer and attach the object to a record definition and field.


Step Two:

Create a new Message in the PeopleSoft Message Catalog for storing the jQuery JavaScript library. Ideally, you should add a new Message Set Number solely for holding javascript. Once you add a new message set, add a new message. Use the following attributes:

Message Number: Whatever number is the next available
Severity: Message
Message Text: jQuery Library
Explanation: Paste the code from jQuery javascript library.

Step Three:
Create an HTML Definition for the JavaScript code that you are going to inject into your page. This HTML Definition will be used to store the javascript code. We will retrieve the HTML and inject into the HTML Area of the page on the next step. In the HTML Definition, at the very top, add the following code.


Step Four:

On the main component where the page is used, add PreBuild PeopleCode to retrieve the message data and inject it onto the HTML Area of the page. This can also be added to the Page Activate PeopleCode if desired. Here is the code:

// Declare my Variables
Local string &jquery;

// ************************************************
// Use MsgGetExplainText to grab the
// jQuery javascript library
// ************************************************
&jquery = MsgGetExplainText(28000, 1, "message not found");

// ************************************************
// Use GetHTMLText to get the HTML and
// Pass the &jquery string which contains
// the jQuery library code. This will inject it
// onto the HTML area of the page
// ************************************************
DERIVED_HR.HTMLAREA.Value = GetHTMLText(HTML.MY_HTML, &jquery, &jform);

You are now ready to add more javascript to your HTML definition and utilize the jQuery library. Using javascript and AJAX within PeopleSoft applications is very powerful and allows you to add robust features to your applications. I suggest that you start experimenting with AJAX and javascript today.

Saturday, February 7, 2009

Import Data from Files Using Application Engine

You can use application engine to import files into tables in your PeopleSoft Database. Prior to version 8, the only way to programmatically do this was by using SQR. However, you now have the ability to create a File Layout Definition object and using Peoplecode, you can load a file directly into your database.

Application Engine is extremely powerful when utilized correctly. For example, you can utilize functionality such as peoplecode, SQL, Do While, Do Until, and Do Select. Therefore, you have the ability to manipulate the data just as you were capable of doing using SQR.

I'm going to walk through loading data from a flat file into a table using Application Engine. This example is a very simple one and is easy to follow. So lets get started!

First and foremost, you will need to create a File Layout Definition.

For this example we are using a table that we have defined in Application Designer named "N_SDN_TBL". This table is constructed as follows:

---------------------- --------------
N_SDN_ID decimal 9,10
N_SDN_NAME char 50
N_SDN_TYPE char 12
N_SDN_SNCTION_PGM char 20
N_SDN_TITLE char 180
N_SDN_VSSL_CALLSGN char 8
N_SDN_VESSEL_TYPE char 25
N_SDN_VSSLTONNAGE char 14
N_SDN_GRT_REG_TON char 8
N_SDN_VESSEL_FLAG char 40
N_SDN_VSSL_OWNER char 150
N_SDN_REMARKS char 254

When you define a File Layout, you can define it with a format of FIXED, CSV, or XML. In this Example we are using Fixed. From Application Designer, simply create a new File Layout object. Right click on the File Layout and Insert a Record. For this example we choose N_SDN_TBL. Once you choose the record App Designer will add the record and its fields to the layout.

The Next step is to adjust the start and ending positions for each field. Simply double click on a field and enter the start and ending position for this field the way it is in your flat file. Once you go through and complete this process for each field you can save your file layout and start building your application engine program.

All we need for this program are two simple steps.

The first step will be a simple SQL step to truncate the table N_SDN_TBL.Second, we add another step for PeopleCode. The PeopleCode for loading this data into the table is written below.


/**********************************************************
FUNCTION TO IMPORT DATA
**********************************************************/
Function ImportSegment(&RS2 As Rowset, &RSParent As Rowset)
Local Rowset &RS1, &RSP;
Local string &RecordName;
Local Record &REC2, &RECP;
Local SQL &SQL1;
Local integer &I, &L;
&SQL1 = CreateSQL("%Insert(:1)");
&RecordName = "RECORD." | &RS2.DBRecordName;
&REC2 = CreateRecord(@(&RecordName));
&RECP = &RSParent(1).GetRecord(@(&RecordName));
For &I = 1 To &RS2.ActiveRowCount
&RS2(&I).GetRecord(1).CopyFieldsTo(&REC2);
If (EditRecord(&REC2)) Then
&SQL1.Execute(&REC2);
&RS2(&I).GetRecord(1).CopyFieldsTo(&RECP);
For &L = 1 To &RS2.GetRow(&I).ChildCount
&RS1 = &RS2.GetRow(&I).GetRowset(&L);
If (&RS1 <> Null) Then
&RSP = &RSParent.GetRow(1).GetRowset(&L);
ImportSegment(&RS1, &RSP);
End-If;
End-For;
If &RSParent.ActiveRowCount > 0 Then
&RSParent.DeleteRow(1);
End-If;
Else
&LOGFILE.WriteRowset(&RS);
&LOGFILE.WriteLine("****Correct error in this record and delete all error messages");
&LOGFILE.WriteRecord(&REC2);
For &L = 1 To &RS2.GetRow(&I).ChildCount
&RS1 = &RS2.GetRow(&I).GetRowset(&L);
If (&RS1 <> Null) Then
&LOGFILE.WriteRowset(&RS1);
End-If;
End-For;
End-If;
End-For;
End-Function;



Rem *****************************************************************;
rem * Define our Objects *;
rem *****************************************************************;
Local File &FILE1
Local Record &REC1
Local SQL &SQL1
Local Rowset &RS1
Local integer &M


/******************************************************************/
/* LOAD A FILE CALLED SDN.FF */
/******************************************************************/

/* CREATE A HANDLE TO THE FILE AND THE LOGFILE SETTING THE ATTRIBUTES */

&FILE1 = GetFile("D:\FS800\N_INTERFACES\SDN\SDN.FF", "r", "a", %FilePath_Absolute);
&LOGFILE = GetFile("D:\FS800\N_INTERFACES\SDN\SDN.FF.err", "W", %FilePath_Absolute);

/* LOAD OUR FILELAYOUT TO THE FILE HANDLE */

&FILE1.SetFileLayout(FileLayout.N_SDN_TBL);
&LOGFILE.SetFileLayout(FileLayout.N_SDN_TBL);

/*************************************************************
CREATE A ROWSET FOR THE FILE AND ONE FOR THE RECORD THAT WE
WILL BE LOADING THEN READ EACH ROW OF THE FILE AND INSERT
IT INTO OUR TABLE
**************************************************************/

&RS1 = &FILE1.CreateRowset();
&RS = CreateRowset(Record.N_SDN_TBL);
&SQL1 = CreateSQL("%Insert(:1)");
&RS1 = &FILE1.ReadRowset();

While &RS1 <> Null;
ImportSegment(&RS1, &RS);
&RS1 = &FILE1.ReadRowset();
End-While;

&FILE1.Close();
&LOGFILE.Close();

I hope that this example was helpful in providing you a simple, quick, and easy way
to load data from a fixed field length flat file into a table. There really is no need to continue to do these types of applications using SQR. You should start programming using Application engine for any type of process that does not require a fancy report. Remember, Application Engine programs are objects that you can upgrade. SQR's are not.

Monday, January 26, 2009

Some useful SQLs in PeopleSoft

--the permission lists associated to a user
SELECT A.OPRID, D.ROLEUSER, B.ROLENAME, B.CLASSID, C.ClASSDEFNDESC
FROM PSOPRDEFN A, PSROLECLASS B, PSCLASSDEFN C, PSROLEUSER D
WHERE A.OPRID=D.ROLEUSER AND B.CLASSID=C.CLASSID AND B.ROLENAME=D.ROLENAME AND A.OPRID= 'SPNR0000'
ORDER BY B.CLASSID;


-- The Value corresponding to a Process Run Status
SELECT XLATLONGNAME, FIELDVALUE FROM PSXLATITEM WHERE FIELDNAME = 'RUNSTATUS';

-- To get the processing time
SELECT
PRCSINSTANCE,
PRCSNAME,
OPRID,
RUNSTATUSDESCR,
DECODE (FLOOR(TO_CHAR((enddttm-begindttm)*24*60))||':'||LPAD(FLOOR(((TO_CHAR((enddttm-begindttm)*24*60))- FLOOR(TO_CHAR((enddttm-begindttm)*24*60)))*60) ,2,0), ':',' ',FLOOR(TO_CHAR((enddttm- begindttm)*24*60))||':'||LPAD(FLOOR(((TO_CHAR((enddttm-begindttm)*24*60))-FLOOR(TO_CHAR((enddttm-begindttm)*24*60)))*60) ,2,0)) AS MINSEC
FROM PS_PMN_PRCSLIST
WHERE runstatusdescr ='Success';

Sending Mails Without SMTP Server

MCF class does not need app server SMTP server and Port settings

import PT_MCF_MAIL:SMTPSession;
import PT_MCF_MAIL:MCFEmail;
import PT_MCF_MAIL:MCFMultipart;
import PT_MCF_MAIL:MCFBodyPart;
import PT_MCF_MAIL:MCFPart;
import PT_MCF_MAIL:*;

&OuboundEmail = create PT_MCF_MAIL:MCFOutboundEmail(); &OuboundEmail.smtpserver = "";
&OuboundEmail.SMTPPort = 25;
&OuboundEmail.from = "xyz@abc.com";
&OuboundEmail.recipients = 'pqr@lmn.com';
&OuboundEmail.subject = "Test Subject";
&OuboundEmail.text='' ;
&ret = &OuboundEmail.send();

Hide The Grid Using PeopleCode

Local Rowset &Rowset = GetLevel0()(1).GetRowset(Scroll.AA_OVRD_WHERE);
rem &Rowset.HideAllRows();

[or]

For &I = 1 To &Rowset.ActiveRowCount
&Rowset.GetRow(&I).Visible = False;
End-For;

Number to Word

Converting number to words...

1.

select CASE WHEN LENGTH(1234567892) >= 10 THEN initcap(to_char(to_date(substr(ROUND(1234567892),1,3),'J'),'JSP')) ' Crore ' initcap(to_char(to_date(substr(ROUND(1234567892),length(ROUND(1234567892))-6,2),'J'),'JSP')) ' Lakh ' initcap(to_char(to_date(substr(ROUND(1234567892),length(ROUND(1234567892))-4,5),'J'),'JSP')) WHEN LENGTH(ROUND(1234567892)) = 9 THEN initcap(to_char(to_date(substr(ROUND(1234567892),1,2),'J'),'JSP')) ' Crore ' initcap(to_char(to_date(substr(ROUND(1234567892),length(ROUND(1234567892))-6,2),'J'),'JSP')) ' Lakh ' initcap(to_char(to_date(substr(ROUND(1234567892),length(ROUND(1234567892))-4,5),'J'),'JSP')) WHEN LENGTH(ROUND(1234567892)) = 8 THEN initcap(to_char(to_date(substr(ROUND(1234567892),1,1),'J'),'JSP')) ' Crore ' initcap(to_char(to_date(substr(ROUND(1234567892),length(ROUND(1234567892))-6,2),'J'),'JSP')) ' Lakh ' initcap(to_char(to_date(substr(ROUND(1234567892),length(ROUND(1234567892))-4,5),'J'),'JSP')) WHEN LENGTH(ROUND(1234567892)) = 7 THEN initcap(to_char(to_date(substr(ROUND(1234567892),length(ROUND(1234567892))-6,2),'J'),'JSP')) ' Lakh ' initcap(to_char(to_date(substr(ROUND(1234567892),length(ROUND(1234567892))-4,5),'J'),'JSP')) WHEN LENGTH(ROUND(1234567892)) = 6 THEN initcap(to_char(to_date(substr(ROUND(1234567892),length(ROUND(1234567892))-6,1),'J'),'JSP')) ' Lakh ' initcap(to_char(to_date(substr(ROUND(1234567892),length(ROUND(1234567892))-4,5),'J'),'JSP')) WHEN LENGTH(ROUND(1234567892)) < class="blsp-spelling-error" id="SPELLING_ERROR_47">initcap(to_char(to_date(substr(ROUND(1234567892),length(ROUND(1234567892))-4,5),'J'),'JSP')) END as words FROM DUAL

2.

select initcap(to_char(to_date(1234567,'J'),'JSP')) from dual
This would produce the following output:
One Million Two Hundred Thirty-Four Thousand Five Hundred Sixty-Seven
This usual approach matches with Indian system till tens of thousands.

About PeopleSoft DataBase

Peoplesoft Database separated into 3 parts....

1.System Catalog
2.PeopleTools
3.Application Data

System Catalog records the information about the database and its content. means Table Names, Column Names and Index Names Etc...
it contaions Database Metadata. it tracks all objects in entie database.
Ex:-DBA_OBJECTS.

PeopleTool record the information about the defination thats make up our peopleSoft Appliacation , which means its stores record names, page names annd component names etc.... it contains metadata about the peopleSoft application installed on the database.

Application Data records the information which is entered by the customers.

Webserver presents the Data.

Appserver validates the Business Logic.

Database Server stores and updates the data.