Defining Generic Templates

To define generic templates, use the Generic Templates (WL_TEMPLATE_GEN) component.

This section provides an overview of generic templates.

You can call generic templates from any PeopleCode program. Use generic templates when a component template does not meet your requirements. For example, you might use generic templates when developing:

  • Application Engine PeopleCode.

  • Service Operation handler PeopleCode.

  • Notifications being sent in the background in a component, for which the user is not prompted with the Send Notification page.

  • Applications that need to have more control of the Send Notification page to set default To, CC, or BCC values, or to set default message text that is editable.

  • Applications that need to send HTML email.

Note: The SYSTEMDEFAULT generic template is a special case. It is used by the Notify toolbar button on all components if there are no other component templates defined for that component. You cannot add template variables for SYSTEMDEFAULT. Two template variables are available for this template: %1, which generates a component URL for the page with only search keys from which the Notify button is selected; and %2, which generates a component URL for the page with both search keys and alternate search keys. Do not change this template unless you want to make a system-wide change.

To access the Generic Template Definition page, select PeopleTools, Workflow, Notifications, Generic Templates, Generic Template Definition.

Image: Generic Template Definition page

This example illustrates the fields and controls on the Generic Template Definition page.

Generic Template Definition page

The pages and fields in the Generic Templates component are the same as those for defining the notification templates, except for two key differences:

  • A generic template does not reference any information from the template variables component.

    Add template variables directly to the generic template explicitly by adding rows in the template variables grid.

  • A generic template does not support Additional Recipients.

    This statement is true because the generic template is not used to launch the Send Notification page, which is where the additional recipients appear.

To use a generic template from a component, you do not select a Notify check box in the component properties dialog box. You must create a button and use PeopleCode to specify which generic template to use. Furthermore, you must pass in data that is needed by the template to populate template variables.

Template variables are placeholders in the template that can be populated with data passed in with PeopleCode. The order of the data being passed must match the order of the corresponding variables in the Template Variables grid. Thus, the suggested naming for these variables is %1, %2, and so on. This naming convention is consistent with the Message Catalog use of variables.

Generic templates other than SYSTEMDEFAULT are usually used only in PeopleCode calls. The following sample code shows how to use a generic template called MYTEMPLATE to send out a notification:

import PT_WF_NOTIFICATION:NotificationAddress;
import PT_WF_NOTIFICATION:Notification;
import PT_WF_NOTIFICATION:NotificationTemplate;
Local array of string &aryValues;
Local array of NotificationAddress &mynotifyto;
Local NotificationAddress &mynotifyaddress;
Local Notification &mynotification;
&mynotifyto = CreateArrayRept(&mynotifyaddress, 0);
&emailid = "targetperson@example.com";
&mynotifyaddress = create NotificationAddress("", "", "", &emailid, "Email");
&mynotifyto.Push(&mynotifyaddress);
&mynotifytemplate = create NotificationTemplate("","", "MYTEMPLATE", "G");
/* Populate an array to contain the values needed by the template */
&aryValues = CreateArrayRept("", 0);
&aryValues.Push("FIRST VALUE");
&aryValues.Push("SECOND VALUE");
&xmlVars = &mynotifytemplate.SetupGenericVars(&aryValues);
&mynotifytemplate.GetAndExpandTemplate(%Language, &xmlVars);
/* At this point, the &mynotifytemplate should have every value resolved */
&mynotification = create Notification("sourceperson@example.com", %Date + %PerfTime, %Language);

Note: To ensure a unique timestamp for each notification that is sent,you must pass a DateTime value that includes milliseconds to the dttmCreated parameter. Because the %Datetime system variable always returns 0 for the milliseconds value, use the combination of %Date+%PerfTime instead.

See %Date, %PerfTime.

&mynotification.NotifyTo = &mynotifyto;
&mynotification.Subject = &mynotifytemplate.Subject;
&mynotification.Message = &mynotifytemplate.Text;
&mynotification.Send();

Note: You can also use this code for component templates by replacing the G with a C. Then, populate the component name and market when calling the template as shown in the following example code. The template variables are all assumed to be in the page buffers.

&mynotifytemplate = create NotificationTemplate(%Component, %Market, "MYCOMPONENTTEMPLATE", "C");
&xmlVars = &mynotifytemplate.SetupCompVarsAndRcpts(GetLevel0());
&mynotifytemplate.GetAndExpandTemplate(%Language, &xmlVars);