Saturday, April 28, 2012

Send Email with Color..

send emails with colours, tables and graphics, you have come to the right place. This post explains how to send html emails from peoplecode using the html option in sendmail. This can generate really good looking emails that stand out from the usual text only emails used for notifications. So here’s how we do it.
Local string &NL = "<br>"; /* The new line character in html */
/* Setting the parameters for sendmail */
&MAIL_FLAGS = 0;
&MAIL_TO = "email1@psoftsearch.com";
&MAIL_CC = "email2@psoftsearch.com";
&MAIL_BCC = "email3@psoftsearch.com";
&MAIL_SUBJECT = "Test Email";
&MAIL_FILES = "";
&MAIL_TITLES = "";

/* Making the email body */
&GREET = "<font face ="Arial">Dear " | &f_name | " " | &l_name | "," | &NL;
&MAIL_TEXT1 = "This is a test email that contains an HTML table." | &NL;
&MAIL_TEXT2 = "<table border='1'><tr bgcolor = '#AAAAAA' ><th>Name</th><th>State</th><th>Country</th></tr><tr><td>Rojer Alex</td><td>VA</td><td>USA</td></tr></table>" | &NL;
&TEXT1 = "Your footer line(s) goes here." | &NL | &NL;
&TEXT2 = "Regards," | &NL | "The PSoftSearch team";
&MAIL_FOOTER = &TEXT1 | &TEXT2 | "</font>";
&MAIL_TEXT_BODY = &MAIL_GREET | &MAIL_TEXT1 | &MAIL_TEXT2 | &MAIL_FOOTER;

/* Sending the email */
&RET_CODE = SendMail(&MAIL_FLAGS, &MAIL_TO, &MAIL_CC, &MAIL_BCC, &MAIL_SUBJECT, &MAIL_TEXT_BODY, &MAIL_FILES, &MAIL_TITLES, "", ";", "Content-type: text/html; charset=utf8");

/* Evaluating the return value of sendmail and showing the appropriate message */
If (&RET_CODE = 0) Then
MessageBox(0, "Alert", 0, 0, "Email has been sent.");
Else
MessageBox(0, "Alert", 0, 0, "Unable to send email.");
End-If;

Populating Data into Grid...

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 */
PeopleSoft Component Interface (CI) exposes a PeopleSoft Component for synchronous access to other applications written in PeopleCode, Java or C++. We can consider CI as the means by which PeopleSoft enforces encapsulation by limiting external access to just what is made available through the CI and nothing more.
A CI also executes the business logic included in the Component. As such, it provides a higher level of data validation to the data that is being loaded into the Component when compared to direct SQL inserts.
PeopleSoft also provides a Component Interface Tester to validate the CI and Excel To CI to manage loading data.
You can have as many CIs pointing to a Component as you want. But a Component Interface can point to only one Component.
Attributes of a Component Interface
A Component Interface has the following five attributes.
  • Name
  • Keys
  • Properties
  • Collections
  • Methods
Name
The Name of the Component Interface is the unique name by which we can identify the CI. Calling the CI is also done with the help of this name.
Keys
These are special properties that can retrieve the values from a CI. The three types of keys that a Component Interface has are the following:
Get Keys: These keys return one instance of the Component Interface. These keys are created based on the search record and map to the Search Keys in the search record.
Find Keys: These keys return a list of instances of the CI. These too are created based on the search record and map to the combination of Search Keys and Alternate Search Keys of the Search record.
Create Keys: Create keys are created only when the associated Component has the Add action enabled.
Properties
Properties of a CI provide access to the Component InterfaceĆ¢€™s settings and the data from the underlying Component. We can broadly classify properties into two:
Standard Properties: There are some properties that get assigned automatically when a CI gets created. These standard properties cannot be viewed through the Application Designer. Some examples for such properties are InteractiveMode, GetHistoryItems etc.
User Defined Properties: These properties map to the record fields on the Component. These are displayed in Application Designer and you can choose the properties that need to be included in the Component Interface.
Collections
This is a special property that corresponds to a scroll area. It can contain fields or subordinate scrolls, as is the case in the Component. The default name of a collection would be same as that of the primary record for the underlying scroll.
Methods
Methods are functions that perform a specific task on a CI at runtime. Runtime access to each method is governed by the security level that you have for the specific method. Like Properties, Methods too can be classified into two:
Standard Methods: These are the methods that are available for all CIs. Certain standard methods like Find, Get, Save and Cancel get created automatically when CI is created. The Create method is created only if the underlying Component has the Add action enabled.
User Defined Methods: In addition to the standard methods, we can create our own functions and expose them through the CI as methods for added functionality. Such methods are called user-defined methods. Each user defined method maps to a function. Such methods are highlighted in blue in the Component Interface Designer.