PSoftPros

Derek Tomei

Injecting Javascript & AJAX into a PeopleSoft Page

Last time I discussed using AJAX with PeopleTools. To refresh your memory, 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.[1] Data is retrieved using the XMLHttpRequest object or through the use of Remote Scripting in browsers that do not support it. Despite the name, the use of JavaScript, XML, and asynchrony is not required.

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.

Share 

2 Comments

Jim Marion Comment by Jim Marion on January 6, 2009 at 1:11pm
Hi Derek,

Your blog post looks amazingly similar to John Wagenleitner's AJAX and PeopleSoft post from September 23, 2007. My comments on John's post apply to your post equally.

While this is certainly a good alternative for developers that don't have access to the web server file system, it does not take advantage of the client side browser cache. I suggest a variation on this theme: move the GetHTMLText call into an IScript. Serving the JavaScript library from an IScript rather than inserting it into each page will turn the JavaScript library into an external resource that can be downloaded once and cached in the browser. By folding it into the PeopleSoft page source, you loose the ability to cache the JavaScript library between PeopleSoft pages.

John's post also contains comments about packing versus minification.

You might be interested in a post I just published with a very, very similar title, Injecting JavaScript Libraries into PeopleSoft Pages, that shows how to make JavaScript libraries and modifications available to all PeopleSoft pages by modifying a single managed object. I apologize for the similarities in titles.
Jim Marion Comment by Jim Marion on January 6, 2009 at 1:22pm
Derek, I have been trying to follow your example, but it appears to be missing something: the source for HTML.MY_HTML. You appear to be passing the jQuery source into an HTMLdefinition. Based on comments left by readers of John's post, it appears that the %Bind(:1) script syntax example could be very useful for the PeopleTools community.

Add a Comment

You need to be a member of PSoftPros to add comments!

Join this social network

Newsletters


Sign up for our FREE
PeopleSoft
Newsletter!


Email Address:
 


Latest Activity

Looking for PeopleSoft Financial Consultant(s) with minimum of 5 years experience as a Business Analysis/Functional Lead at version 8.4 (Web Brower) or higher. Must have successfully completed a minimum of 2 PeopleSoft Financial Management instal...
Bradford A Miller and Pat Parekh joined Derek Tomei's group4 hours ago
A group for PeopleSoft recruiters to communicate and work together to fill their open PeopleSoft positions
Bradford A Miller updated their profile5 hours ago
Bradford A Miller, Venu Raman, pathakamuri gowtham and 14 more joined PSoftPros5 hours ago
Lawrance and Agostina Cecilia Laguzzi joined Derek Tomei's groupon Saturday
Join the PeopleSoft Financials group to share and collaborate with other PeopleSoft Financial pro's
Trina Guha updated their profileon Thursday
Thomas V Spol updated their profileon Thursday
Chance Keliiliki updated their profileon Wednesday

© 2009   Created by Derek Tomei

Badges  |  Report an Issue  |  Privacy  |  Terms of Service