Using MsgGetText to Concatenate Strings

Lately, I’ve been using the MsgGetText() built-in function to concatenate adhoc strings in PeopleCode. For example, instead of the following:


Local string &TEXTLINE = "Value of " | &fld1name | " is " | &fld1value | ".";

Using MsgGetText, it can be re-written as follows:


Local string &TEXTLINE = MsgGetText(0, 0, "Value of %1 is %2.", &fld1name, &fld1value);

I find that the latter is easier to read and modify compared to the first, especially if there are a lot of values being concatenated.

What about performance? Wouldn’t the MsgGetText code needlessly query the database for message (0, 0)? Fortunately, I think not. Some tests with SQL trace turned on — and the cache freshly cleared — show that a query to the message catalog for message (0, 0) is never performed by the application server. A wonderful optimization.

Overloading %SubmitScriptName

As discussed in the previous post, all actions in a component that eventually require a server trip would invoke %SubmitScriptName for submitting the page. As such, it sometimes provide a convenient point for performing javascript modifications on the page.

This is achieved by storing a reference to the original function, and redefining %SubmitScriptName to perform your custom logic — invoking the original function as needed.

The following sample scenarios may help to illustrate this technique.
Continue reading

Inserting a New Scroll Row from within the Same Scroll

In PeopleCode, when inserting or deleting a row on a scroll, it is required that you perform the action on a parent row of the rowset being inserted/deleted to. PeopleTools doesn’t allow PeopleCode (using the built-in functions/methods InsertRow and DeleteRow) to insert or delete a row on the same scroll within which it is currently running. If you attempt to do this, PeopleTools will give an error complaining about changing the current program context.

However, there are some cases where inserting within the same scroll might be desirable. For example, based on the data entered on a row of a scroll, a new matching row must be inserted within the same scroll.

Yes, you can always make concessions, like forcing the user to click a button on a higher scroll level. Yet if you are looking for a way to insert within the same scroll level, read on. This tutorial illustrates a technique for doing a row insert from PeopleCode to the same scroll where the PeopleCode program is running.
Continue reading

Rich emails using SendMail()

PeopleTools 8.4x added an option in the PeopleCode function SendMail() for specifying the content-type. In PeopleBooks, what is immediately highlighted is the ability to format your emails using HTML by setting the content-type to text/html. What probably isn’t well known is that it is also possible to set the content-type to other MIME types such as multipart/related.

text/html alone will allow you to format the text of your message. But if you need to display an image such as a logo, <img> tags inside your html will need to link to images stored in a web server somewhere. Sometimes, this is not ideal. With multipart/related, you can embed images in your email messages.

Continue reading

Emails w/ Attachment From a PS Online Page

The PeopleCode SendMail() function is a quick and easy way to send emails from your PeopleSoft application. Unlike workflow routing and Notification classes, SendMail() provides the most functionality when it comes to sending emails. Over the newer releases, PeopleSoft has further added new capabilities to this function like overriding the content-type and sender details. However, the feature that I find the least used is the inclusion of file attachments. This is because in PIA, PeopleCode runs either on the Application server or the Batch server. The files that can be attached should be either 1) located on the server, or 2) accessed by the server through a network share. For this reason, most applications that use file attachments are Application Engine programs (running on the Batch server) that attach log files from within the server.

If you’ve used web-based email services like Yahoo, then you’ll find it a common feature to allow attachments to be uploaded by a user from his workstation and send those attachments with the email message. Is this possible in PeopleSoft’s internet architecture? The answer is yes, this article will show you how.

Continue reading